- Home /
Having Physics.Raycast rotate with the gameObject
I am having issues with trying to get the Raycasts to rotate with the gameObject they are casting from. They basically just need to cast at an 180 and 90 degree angle and rotate with the gameobject.
Any advice would be highly appreciated, thanks.
Answer by Owen-Reynolds · May 22, 2011 at 10:22 PM
Raycasts use a point and a direction (or else a Ray, which is built using a point and a direction.) I assume you can find the point -- all you need is the direction.
transform.forward
, transform.right
and so on, give you the local directions from yourself. So Physics.Raycast(transform.position + Vector3.up, transform,forward);
does a raycast starting 1 unit above you, the way you are looking.
The get angles, can use tricks like transform.forward - transform.right*0.2f
(aims at a point a little left of you.)
Transform has properties for up forward and right. You can use the inverse of these to get the opposites like left. Though this might help someone who tries to use .left and nothing appears.
Answer by Jesvest · Jun 30, 2011 at 11:00 AM
Why cant i see the rest of the answer from Owen Reynolds when i press the more button?
thats all there is to it, more simply means more information regarding the post (amount of words, comments)
Also please do not post a question as an answer, rather click add new comment on the bottom right hand of the answer or question. If you continue to do this you will be flagged. Thank you,
Your answer
Follow this Question
Related Questions
Picking up few different objects 0 Answers
Stop picked up object clipping through walls? 0 Answers
Having a RaycastHit event create a component? 1 Answer
Problem With RayCast 3 Answers
thousands of raycasts in nested for loop 0 Answers