Hey all,
I'm working on a 3D flight model for a space game at the moment. I had a more Newtonian version of it working well, but it's hardly fun to play, and thus I am trying to introduce a damping force that will reign in the velocity quickly. It's a little more complicated than that though.
- A constant damping force against any movement, but which the force applied to the object (thrusters of a sci-fi nature, i.e. no reduction of mass) can overcome until the max velocity is reached. I'd prefer for that maximum to be emergent based off of force against mass, but not sure on the algorithmic side.
- I have programmed the ability to set a desired speed, which the ship will attempt to maintain. When the ship pitches, I want to keep more close/tight into the curve. At the moment, the change in direction simply adds the force in that direction, with the ship already travelling along the axis it was originally facing, at the original velocity, leading to a diagonal flight path, not straight up. How do I get it to be more responsive in this way? More damping, but how?
Here is my UpdatePhysics() function. The force is reset as the thrusters are only adding force if a key is pressed (or if trying to maintain the desired speed), but the damping doesn't seem to work (I've tried with a number between 0 and 1. Only seems to get results with numbers like 50, but even then the slowing is scaled).
// Velocity Verlet method:
m_lastAcceleration = m_avgAcceleration;
transform.position += m_velocity * Time.deltaTime + (0.5f * m_lastAcceleration * Mathf.Pow(Time.deltaTime, 2));
m_frictionForce = m_thrustDamping * m_velocity * -1.0f;
m_newAcceleration = (m_force + m_frictionForce) / mass;
m_avgAcceleration = ( m_lastAcceleration + m_newAcceleration ) / 2;
m_velocity += m_avgAcceleration * Time.deltaTime;
m_force = Vector3.zero;
I'm honestly not sure if the damping is the right way to go. I just want a less crazy / drifting model, and thus something that a player can actually control.
Any ideas with this?
Regards,
- HateDread.
EDIT: Actually the most significant parts could be accomplished by keeping track of that set speed / desired speed for movement along the Z (forwards and back), but just adding force on the strafing. How can I damp the X and Y axes but not the Z? If that's what I should do, that is.