This seems simple enough, but I’m a bit stuck…
I want to calculate the distance the player has moved in a particular direction per frame to update the score (the player gains points for the farther they move in the correct direction).
The direction is a Vector3 that changes every frame (the course is curvy). The player is a Rigidbody, so I can access velocity as well.
I’ve been trying to calculate the percent that the player velocity matches the direction and use that like this:
float degreesDiff = Vector3.Angle(nDirection, nVelocity);
float percentDiff = 1.0f - (degreesDiff / 360.0f);
float movementForward = rigidbody.velocity.magnitude * percentDiff;
No surprise, this doesn’t work (straffing pumps up the velocity magnitude and then the percent doesn’t mater).
What am I missing guys? Can I use a dot product or something for this?
Cheers