- Home /
Raycast in the wrong way
Hello
Please i have a problem with my raycast, when i cast a ray, it didn't follow the direction of my player, for exemple when i turn back my player, the ray continue to cast in back of it, it don't turn with my player
I have wrote this line
fwd = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position,fwd,Color.red);
if ( Input.GetMouseButtonDown(0)) {
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd,out hit)) {
here's a picture to better understand
http://www.hostingpics.net/viewer.php?id=475857CastProblem.png
thank you
Answer by Berenger · May 17, 2012 at 04:12 PM
fwd = transform.TransformDirection(Vector3.forward); and transform.forward are the same thing.
Are you sure that script is attached to the transform performing the rotation or to one of it's child ?
Answer by Statement · May 17, 2012 at 04:15 PM
I guess your objects forward vector differs from your models facing? Just use fwd = -transform.forward;
in that case.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071622im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why i can't see my questions ? 2 Answers
Skyboxes, GetPixel and Raycast Directions 1 Answer
Vector direction for a reticle 1 Answer
My bullets arent going the right direction 1 Answer
Collision InFront? 1 Answer