3D constant damping force that dictates maximum velocity?

Started by
1 comment, last by ferrous 10 years, 4 months ago

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.

Advertisement

Hmm, interesting stuff. No real right answer. As for making it feel more responsive, maybe adjusting the damping force. The assumption I'm making here is that the player probably has just one thrust direction they use (like asteriods?), in which case you could do a dot product between that new incoming thrust and the existing velocity of the ship, and scale the existing dampening of the velocity by the inverse of the dot? It's kind of hacky, but might work.

As for the top speed? It's easier usually just to cap the max velocity, but maybe someone else has an idea?

EDIT: Instead of thrust, I think the ship's current orientation might be more useful? It would give the ship a tendency to always want to move forward, almost like it was in some sort of flow field orientating about it.

Oh, one further thought:

Actually, taking the ships current facing/direction/thrust. (Again assuming a ship with a non positional thruster on it's rear, like the ships in Wing Commander / Asteriods / X-wing) One could do a projection to separate the velocity vectors that are parallel and perpendicular to the ship's current heading, and just dampen the perpendicular forces more than the parallel forces.

This topic is closed to new replies.

Advertisement