- Home /
Why does the normal vector come out like this when I shoot a ray while walking backwards?
I'm going to implement a gun.
I want to implement the Particle system, so I need the normal vector of the hit place.
If I shoot a ray while walking forward, it works properly, but if I shoot a ray while walking backwards, the hit.normal bounces in a strange direction and can't be implemented properly.
What's the reason for this?
RaycastHit hit = new RaycastHit();
Ray r = new Ray(Camera.main.transform.position , Camera.main.transform.forward );
Vector3 hitPosition = r.origin + r.direction * 200.0f;
if (Physics.Raycast(r, out hit))
{
Debug.DrawLine(r.origin, r.origin + r.direction * 200.0f, Color.green);
Debug.DrawLine(hit.point, hit.normal, Color.red);
}
forward
backward
This situation is when the camera looks forward and steps back.
forward.jpg
(21.1 kB)
backward.jpg
(35.9 kB)
Comment
Your answer
Follow this Question
Related Questions
Health System Raycast Bullets 2 Answers
Raycast hitting collider even though its set to trigger? 1 Answer
Prevent Raycast on reacting to GUI input? 2 Answers
Noob Raycast question 0 Answers