- Home /
rotating ray with player rotation.
What I am trying to achieve is to get a ray to follow the players global? rotation and face the direction the cube is at the moment it points the same direction even when the cube rotates ill show you the script
void Update ()
{
RaycastHit hit = new RaycastHit();
Debug.DrawRay(transform.localPosition, Vector3.right * 10);
if (Physics.Raycast(transform.position, Vector3.right, out hit, 10.0f))
{
Debug.Log(hit.transform.name);
}
}
Generally, You want to cast a ray and hit the transform.position, and when it hits it so it'll debugLog..?
Answer by Eric5h5 · Jul 03, 2010 at 02:36 AM
Use transform.forward
instead of Vector3.right
(assuming you want the ray to be cast in the object's z direction). Vector3.right
is world space.
argghgh damnit! i knew it was something i had already tried, thank you so much!
Answer by saadali211 · Feb 22, 2018 at 06:48 PM
Here is the video about what you are looking for
Solved '· Jul 03, 2010 at 02:36 A$$anonymous$$' okay i think you dont need to answer :D
Your answer
Follow this Question
Related Questions
Raycasting from object rotation? 1 Answer
How to incorporate a rotation towards mouse position in this script? I tried 0 Answers
Making My Raycast Face The Right Direction 3 Answers
How to get Ray rotation from direction 0 Answers
Objects Rotation to modify Objects transform velocity/Direction of travel 1 Answer