//Choose which integration method you want to use to simulate how the bullet fly public static void CurrentIntegrationMethod(float timeStep, Vector3 currentPos, Vector3 currentVel, out Vector3 newPos, out Vector3 newVel) { //IntegrationMethods.BackwardEuler(timeStep, currentPos, currentVel, out newPos, out newVel); //IntegrationMethods.ForwardEuler(timeStep, currentPos, currentVel, out newPos, out newVel); //IntegrationMethods.Heuns(timeStep, currentPos, currentVel, out newPos, out newVel); IntegrationMethods.HeunsNoExternalForces(timeStep, currentPos, currentVel, out newPos, out newVel); }
//Easier to change integration method once in this method public static void CurrentIntegrationMethod( float h, Vector3 currentPosition, Vector3 currentVelocity, out Vector3 newPosition, out Vector3 newVelocity) { //IntegrationMethods.EulerForward(h, currentPosition, currentVelocity, out newPosition, out newVelocity); IntegrationMethods.Heuns(h, currentPosition, currentVelocity, out newPosition, out newVelocity); //IntegrationMethods.RungeKutta(h, currentPosition, currentVelocity, out newPosition, out newVelocity); //IntegrationMethods.BackwardEuler(h, currentPosition, currentVelocity, out newPosition, out newVelocity); }
public void MoveSphereOneStep() { float timeStep = Time.fixedDeltaTime; IntegrationMethods.Heuns(timeStep, currentPos, currentVel, transform.up, bulletDataa, out nextPos, out nextVel); currentPos = nextPos; currentVel = nextVel; transform.position = currentPos; transform.forward = currentVel.normalized; }
void MoveBulletOneStep() { //Use an integration method to calculate the new position of the bullet float timeStep = Time.fixedDeltaTime; IntegrationMethods.Heuns(timeStep, currentPos, currentVel, transform.up, bulletData, out newPos, out newVel); //Debug.DrawRay(transform.position, transform.up * 5f); //Set the new values to the old values for next update currentPos = newPos; currentVel = newVel; //Add the new position to the bullet transform.position = currentPos; //Change so the bullet points in the velocity direction transform.forward = currentVel.normalized; }