- Home /
ray transform.position goes wrong
ok why does first code not working properly?
Debug.DrawRay (transform.position, new Vector3(transform.position.x + 10, transform.position.y, transform.position.z + 0), Color.red);
Debug.DrawRay (transform.position, new Vector3(transform.position.x + -10, transform.position.y, transform.position.z + 0), Color.red);
Debug.DrawRay (transform.position, new Vector3(transform.position.x + 0, transform.position.y, transform.position.z + 10), Color.red);
Debug.DrawRay (transform.position, new Vector3(transform.position.x + 0, transform.position.y, transform.position.z + -10), Color.red);
this code gives 4 lines in 4 directions correctly
Debug.DrawRay (transform.position, transform.forward*10, Color.red);
Debug.DrawRay (transform.position, transform.forward*-10, Color.red);
Debug.DrawRay (transform.position, transform.right*10, Color.red);
Debug.DrawRay (transform.position, transform.right*-10, Color.red);
why does first code go in 4 direction forward like:
\|/
I don't get it...
sdgd, sometimes it's easier to use Debug.DrawLine .. you just give it from/to positions
oh didn't know there are 2 debugs, ...
I just google for debug ray and I got it so I went on that
Answer by robertbu · Mar 15, 2013 at 06:50 AM
The second parameter is a direction. It is assumed that (0,0,0) is the basis of the vector, so your rays are the direction those positions are from the origin. Try this instead:
Debug.DrawRay (transform.position, new Vector3(10, 0, 0), Color.red);
Debug.DrawRay (transform.position, new Vector3(-10,0, 0), Color.red);
Debug.DrawRay (transform.position, new Vector3(0, 0, 10), Color.red);
Debug.DrawRay (transform.position, new Vector3(0, 0, -10), Color.red);
For example now you have a vector that is +10 on the x axis away from the point specificed as the first parameter. Note that the other four DrawRays() are not the same as these (now edited) four. These four will align with the world axes. The other four will align with the rotation of the block.
ok thanks
and hey BTW I'm able to accept the answer too ;)
yes I got lazy for 1 answer from all my Q haven't touch unity for about 3 weeks and will have to look in to it
but you don't need to accept it ins$$anonymous$$d of me as I always accept answers with witch I'm most satisfied
I wasn't the one to accept your answer. Anyone with enough $$anonymous$$arma can accept answers. Generally I don't mark accepted for my answers, but might for someone else's answers.
Sure ;) Accepting your own answer doesn't give you karma. I barely accept answers since it's the duty of the OP. However i will accept answers which has been posted by the OP on his own question to give him some karma (of course only when the answer makes sense ;)).
Sometimes i accept correct answers to questions that are a year old just to have it closed.
"Sometimes i accept correct answers to questions that are a year old just to have it closed."
Bunn, I'm surprised someone as young as you thinks one year is a year. For me these days two days is a year. I have the same philosophy, I close everything I see that is more than two real days old ;-)
I wonder what the $$anonymous$$arma cut off is to close answers?
I didn't know accepting your own answer doesn't give you $$anonymous$$arma. It make sense.
Your answer
Follow this Question
Related Questions
2 raycasts on the fpwalker/camera 1 Answer
Distribute terrain in zones 3 Answers
Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 1 Answer
[C# / Unity] Raycast Ignoring Self / Offsetting Instantiations? 0 Answers
Raycasting how to find position on end of ray float distance 1 Answer