public static void ApplyPushback(ref Vector3 position, ref Vector3 pushbackVelocity, float deacceleration, PushBackFinishedHandler ev) { if (pushbackVelocity.Length() > 0) { float dt = Game.Instance.Simulation.Time.Dt; // Console.WriteLine("pushback applied: "+pushbackVelocity); Vector3 oldVelocity = pushbackVelocity; // apply de-acceleration pushbackVelocity -= Vector3.Normalize(pushbackVelocity) * deacceleration * dt; // if length increases we accelerate in opposite direction -> stop if (pushbackVelocity.Length() > oldVelocity.Length()) { // apply old velocity again position += oldVelocity * dt; // set zero pushbackVelocity = Vector3.Zero; // inform ev(); } // apply velocity position += pushbackVelocity * dt; } }
public IslandControllerPropertyBase() { OnRepulsionEndAction = new PushBackFinishedHandler(OnRepulsionEnd); }