Is rigidbody going forward?

Hello,
how i check, if rigidbody goes forward? (IF) in script C#…Rigidbody moves in 3D with all directions. Rigidbody isnt connected to camera.

You can take the dot product (with Vector3.Dot()) of whatever you consider “forward” (perhaps transform.forward ?) and the .velocity vector out of the Rigidbody.

If it is positive, you are going forward, otherwise backwards.

This is the nitty gritty on dot products:

2 Likes

Thanks for the reply, it works perfectly!!!

1 Like