public override void _IntegrateForces(PhysicsDirectBodyState state) { var targetPosition = GetNode <RigidBody>("/root/World/Target").GlobalTransform.origin; //GD.Print(state.AngularVelocity); LookFollow(state, GlobalTransform, targetPosition); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { float torque = 0f; if (accelerating) { torque += motorForce; } if (rev) { torque -= revForce; } foreach (Wheel w in wheels) { w.torque = torque; w.steeringAngle = steeringAngle; w.sideFrictionMultiply = drifting ? .5f : 1f; //w.sideFrictionMultiply = 0f; w.UpdateWheel(state); GlobalTransform = state.Transform; LinearVelocity = state.LinearVelocity; AngularVelocity = state.AngularVelocity; } }
// Called when the node enters the scene tree for the first time. public override void _IntegrateForces(PhysicsDirectBodyState state) { float length = (GlobalTransform.origin + StartPosition).Length(); if (length < 0) { length = (-length); } if (length > range) { Explode(); QueueFree(); } if (Dir != null) { state.LinearVelocity = Dir; } else { QueueFree(); } //GD.Print(Dir); //GD.Print(LinearVelocity); //GetCollidingBodies(); }
private void LookFollow(PhysicsDirectBodyState state, Transform currentTransform, Vector3 targetPosition) { Vector3 upDir = new Vector3(0, 1, 0); targetPosition.y = GlobalTransform.origin.y; //Vector3 curDir = new Vector3(0,0,1).Rotated(upDir,GlobalTransform.basis.GetEuler().y); var curDir = currentTransform.basis.Xform(new Vector3(0, 0, 1)); //float rotationAngle = (float)(Math.Atan2(targetDir.z, targetDir.x)-Math.Atan2(curDir.z, curDir.x)); var targetDir = (targetPosition - currentTransform.origin).Normalized(); float angle = Mathf.Atan2(targetDir.x, targetDir.z) - Mathf.Atan2(curDir.x, curDir.z); //Mathf.Atan2(curDir.x,curDir.z) - ; //state.AngularVelocity = curDir.LinearInterpolate(targetDir, TurretSpeed*state.Step); //GD.Print(angle); if (angle > Math.PI) { angle -= 2 * (float)Math.PI; } else if (angle <= -Math.PI) { angle += 2 * (float)Math.PI; } state.AngularVelocity = upDir * (angle) * 10;//(upDir * (rotationAngle / state.Step)); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (state.GetContactCount() > 0) { var colliderObject = (Spatial)state.GetContactColliderObject(0); _worldCoords = colliderObject.GlobalTransform.origin + state.GetContactLocalPosition(0); } }
private void LookFollow(PhysicsDirectBodyState state, Transform currentTransform, Vector3 targetPosition) { var upDir = new Vector3(0, 1, 0); var curDir = currentTransform.basis.Xform(new Vector3(0, 0, 1)); var targetDir = (targetPosition - currentTransform.origin).Normalized(); var rotationAngle = Mathf.Acos(curDir.x) - Mathf.Acos(targetDir.x); state.AngularVelocity = upDir * (rotationAngle / state.Step); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (GetCollidingBodies().Cast <Node>().Any(z => z.Name.Equals("BottomPanePhysics"))) { new System.Timers.Timer() { Enabled = true, AutoReset = false, Interval = 2000 }.Elapsed += (z, zz) => { QueueFree(); }; } }
public override void _IntegrateForces(PhysicsDirectBodyState state) { RigidBody r = (RigidBody)GetParent().GetNode("Target"); var targetPosition = r.GlobalTransform.origin;//GetNode<RigidBody>("Target").GlobalTransform.origin; //var targetPosition = new Vector3(-5,1,-15); //GD.Print(Transform.origin.AngleTo(targetPosition)); //state.AngularVelocity = new Vector3(0,2,0); //state.AngularVelocity = new Vector3(0,0,0); LookFollow(state, GlobalTransform, targetPosition); }
public override void _IntegrateForces(PhysicsDirectBodyState physicsState) { if (ColonyParent != null) { return; } // TODO: should movement also be applied here? physicsState.Transform = GetNewPhysicsRotation(physicsState.Transform); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (IsInstanceValid(target) && TTL > 5) { var targetPosition = target.GetGlobalTransform().origin; LookFollow(state, GetGlobalTransform(), targetPosition); } else { Disable(); } }
public static Vector3 GetVelocityAtPoint( this PhysicsDirectBodyState bodyState, Vector3 worldPoint ) { Vector3 centeredPoint = worldPoint - bodyState.Transform.origin; Quat rotQuat = new Quat(bodyState.AngularVelocity); Transform motionT = new Transform(rotQuat, bodyState.LinearVelocity); Vector3 movedPoint = motionT.Xform(centeredPoint); return(movedPoint - centeredPoint); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { // Turn critter to point in appropriate direction // desiredPosition starts a point directly in front of the critter in world coordinates var desiredPosition = state.Transform.origin - state.Transform.basis.z; desiredPosition += GetComeBackDesiredPosition(state.Transform.origin); desiredPosition += GetFlockingDesiredPosition(state.Transform.origin, neighbours); desiredPosition += GetAvoidObstaclesPosition(state.Transform.origin, obstacles) * 20.5f; var currentQuat = state.Transform.basis.Quat(); var headingQuat = state.Transform.LookingAt(desiredPosition, Vector3.Up).basis.Quat(); bool isStuck = obstacles.Where(obstacle => this.Transform.origin.DistanceSquaredTo(obstacle) < 1).ToList().Count > 0; var force = maxForce; if (obstacles.Count > 0 && isStuck) { force = 1.0f; } else if (ObstacleCount > 0 || CloseNeighbourCount > 0) { force = 0.05f; } var newQuat = currentQuat.Slerp(headingQuat, force); var trans = new Transform(new Basis(newQuat), state.Transform.origin); state.SetTransform(trans); // Push critter in direction that it's facing var forwardForce = GetForwardForce(-state.Transform.basis.z, state.LinearVelocity); state.ApplyCentralImpulse(forwardForce); // Set the desired position line // Lines are drawn in local space (the line is a child of the critter) var desiredPositionLine = this.GetNode <ImmediateGeometry>("desiredPositionLine"); desiredPositionLine.Clear(); desiredPositionLine.Begin(Mesh.PrimitiveType.Lines); desiredPositionLine.AddVertex(Vector3.Zero); desiredPositionLine.AddVertex(state.Transform.XformInv(desiredPosition)); // To convert from global desiredPosition to local desiredPositionLine.End(); }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (Engine.EditorHint) { return; } state.AddCentralForce(state.TotalGravity * Mass); while (forces.Count > 0) { var force = forces.Dequeue(); state.AddForce(force.force, force.position); GetViewport().GetNode <Node>("DebugDraw").Call("draw_box", force.position, new Vector3(0.2f, 0.2f, 0.2f), Colors.Red); } }
public void UpdateWheel(PhysicsDirectBodyState state) { bodyState = state; RaycastProcess(); ClampSuspension(); SuspensionProcess(); DragProcess(); if (motor) { TorqueProcess(); } if (steer) { SteerProcess(); } }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (targetPos != Vector3.Zero && targetPos != null) { state.AngularVelocity = _velocityController.GetAngularVelocity(Transform, targetPos); UpdateLinearVelocity(); if (LinearVelocity != Vector3.Zero) { if (LinearVelocity < new Vector3(0.001f, 0.001f, 0.001f) && LinearVelocity > new Vector3(-0.001f, -0.001f, -0.001f)) { ResetVelocity(); } } } else { Sleeping = true; } }
public override void _IntegrateForces(PhysicsDirectBodyState state) { if (Transform.origin.z > 12 && Transform.origin.x > 6) { x = 0; z = -10; } if (Transform.origin.z < -9 && Transform.origin.x > 6) { x = -10; z = 0; } if (Transform.origin.z < -9 && Transform.origin.x < -16) { x = 0; z = 10; } if (Transform.origin.z > 12 && Transform.origin.x < -16) { x = 10; z = 0; } /* * var bodies= GetCollidingBodies(); * if(bodies.Count != 0){ * GD.Print("h"); * } */ var upDir = new Vector3(x, y, z); var pos = new Vector3(0, 0, 0); //state.AddForce(upDir,pos); state.LinearVelocity = upDir; //new Vector3(-10, 0, -10); //state.AngularVelocity = upDir; //GD.Print(AngularVelocity); }
private void LookFollow(PhysicsDirectBodyState state, Transform currentTransform, Vector3 targetPosition) { var myPosition = currentTransform.origin; var dist = (myPosition - targetPosition).Length(); var _targetDir = myPosition - (myPosition - targetPosition).Normalized(); var targetDir = currentTransform.XformInv(_targetDir); var forward = targetDir.Dot(new Vector3(0, 0, 1)); var rightn = targetDir.Dot(new Vector3(1, 0, 0)); var upn = targetDir.Dot(new Vector3(0, 1, 0)); currentTransform.origin = new Vector3(); float spiral = dist * 0.01f; var worldVelDir = LinearVelocity.Normalized(); var worldTargetDir = currentTransform.Xform(targetDir); var turnRate = 30.0f; if (forward > 0.99f) { GetNode <Particles>("Particles").Emitting = true; var correction = ((worldTargetDir - worldVelDir) * 20.0f) + (Transform.basis.z * 100); state.ApplyCentralImpulse(correction * state.GetStep()); } else { GetNode <Particles>("Particles").Emitting = false; spiral = 0; turnRate = 5; var correction = (worldTargetDir - worldVelDir) * 40.0f; state.ApplyCentralImpulse(correction * state.GetStep()); } float ss = (float)Math.Sin(TTL * 10.0f) * spiral; float cs = (float)Math.Cos(TTL * 10.0f) * spiral; var turn = new Vector3(-upn + ss, rightn - cs, 0) / turnRate; turn = Transform.Xform(turn) - Transform.origin; state.SetAngularVelocity(turn / state.GetStep()); }