How do I check the current relative force of an object, e.g. speed a car is traveling?
if we consider the speed as the amount of velocity in the forward direction, you could use a dot product
speed = Vector3.Dot(rigidBody.velocity, transform.forward);
1 Like
Force and speed are different properties.
- Speed is simply rigidbody.velocity.magnitude. Taking the forward projection would make the value oscillating largely if the car is not moving forward, i.e. drifting or sliding laterally.
- As you’re mixing “force” and “speed” in your question then you may be referring to the momentum, which is mass times velocity. The magnitude of the lineal momentum of the car is simply rigidbody.velocity.magnitude * rigidbody.mass.
I’m not that level but i don’t see how a simple calculated data could make an object drifting unless we use it in a drift formula. And we take the transform.right projection. here, its just a float…
drifting could be obtained by :
- Calculating the sideway speed (A float )
- Calculating Side Friction (A vector3 function of the float above and the transform.right projection using Time.fixedDeltaTime and dividing it by a certain amount to have (or not) a drift/slide behaviour…
- Then Apply the calculated Side Friction as a Force. rigidBody.AddForce(sideFriction).