public override void HandleControlInput(float dt) { if (dt == 0) { return; } if (host.Target != null && host.IsTargetable) { Vector2D direction = (host.Target.Current.Position.Linear - host.Current.Position.Linear).Normalized; DefaultControlHandler.ApplyThrust(dt, host, direction, 1); } else { Vector2D velocity = host.Current.Velocity.Linear; float speed = velocity.MagnitudeSq; if (speed > 0) { speed = (float)MathHelper.Sqrt(speed); Vector2D direction = velocity * (1 / speed); float LAccel = host.MovementInfo.MaxLinearAcceleration.Value * dt; if (speed < LAccel) { DefaultControlHandler.ApplydLV(host, -velocity, dt); //host.Current.Velocity.Linear = Vector2D.Zero; } else { DefaultControlHandler.ApplydLV(host, -direction * LAccel, dt); //host.Current.Velocity.Linear -= direction * LAccel; } } } }
public static void UpdateLinearMovement(float dt, IControlable host) { if (dt == 0) { return; } ControlInput input = host.CurrentControlInput; if (input != null) { if (input[InputAction.MoveForward]) { DefaultControlHandler.ApplyThrust(dt, host, host.DirectionVector, input.ThrustPercent); } else if (input[InputAction.MoveBackwards]) { DefaultControlHandler.ApplyThrust(dt, host, -host.DirectionVector, input.ThrustPercent); } else if (input[InputAction.MoveLeft]) { DefaultControlHandler.ApplyThrust(dt, host, host.DirectionVector.LeftHandNormal, input.ThrustPercent); } else if (input[InputAction.MoveRight]) { DefaultControlHandler.ApplyThrust(dt, host, host.DirectionVector.RightHandNormal, input.ThrustPercent); } else { StopLinearMovement(dt, host); } } else { StopLinearMovement(dt, host); } }