- Home /
Raycast not rotating with object / always have raycast ray a certain way no matter what?
Currently this happens in Unity.
How can I accomplish this?
Answer by Shane8th · Sep 10, 2014 at 01:18 PM
Have you tried using -Vector3.up?
Example something like this, Physics.Raycast (objectPosition, -Vector3.up, out hit, 50.0f);
I just have, this doesn't do the job, remember wherever the object is rotating the raycast has to be cast from the 0 axis of the object, or downward as long as the raycast doesnt move from where it originally was.
Answer by Owen-Reynolds · Sep 10, 2014 at 03:34 PM
This isn't a raycast issue. It's really about local vs. world coords. Raycasts fire whichever direction you ask, so you have to know how to ask for a certain direction.
transform.forward
spins with the player. So if you use it for a raycast direction, the raycast will spin with you. It's known as your "local" forward. Vector3.down
, as Shane suggests, is always real world down; doesn't spin with you; so doesn't care which way you're facing.
Thanks for your response, I used it but forgot to actually respond, thanks for the comment I accepted his answer however because he explained it to me but you just made it a lot more clear.
Thank you, appreciate it. :).
Your answer
Follow this Question
Related Questions
Make an object translate/raycast a certain way disregarding it's rotation 1 Answer
Raycasting, rotating a ray 360 degrees 2 Answers
Turning in a tube with raycast 1 Answer
Smooth rotate around 1 Answer
How do I rotate an object when I press down a key and then it rotates back when I release the key 0 Answers