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 StopLinearMovement(float dt, IControlable host) { 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; } } }