- Home /
Wrong raycast direction on an object which is rotated to match slope terrain
This object is rotated to match the terrain slope by a basic script and moved to the target by NavMeshAgent. When shooting, a raycast should go in direction of the rifle. But, as you see from the photos, the raycast goes as if the object is not rotated at all. The raycast origin is an empty game object which is a child of the rifle's pivot and it is located at the muzzle of the rifle. I tried several things such as changing parent object of raycast origin, but didn't work.
If you have any suggestions, please help me. Thank you.


If you are rotating a NavMeshAgent then my guess is something like this happens every frame:
raycast is performed
NavMeshAgentis rotatedFrame is rendered
NavMeshAgentresets the transform back to it's original orientation
TL;DR: raycast happens at the wrong time.
Your answer
Follow this Question
Related Questions
I am having a problem with my RaycastShooting script. 0 Answers
Trying to keep an object 1.5 above the terrain at all times 1 Answer
Proper way to handle this raycast? 0 Answers
using a textured plane as a cursor, problem successfully rotating relative to RayHit.normal 1 Answer
Drawing a 3d Cone ray 2 Answers