- Home /
Raycast hitInfo not working properly
I'm trying to cast a ray from my camera's origin to the player's (target) position. I was expecting to see a line coming from the camera to the target's bottom, like the green line. But instead what I got was that red line that goes all the way to infinity in the air. The best explanation I could think of is that it's using the user input as a direction to cast the ray to since it seems to follow which ever direction key pressed. Feedback is appreciated. Thanks!
Ray hit;
RaycastHit hitInfo;
Vector3 lookAtPosition = new Vector3(target.position.x, target.position.y - ySlider, target.position.z);
hit = new Ray(transform.position, lookAtPosition);
if(Physics.Raycast(hit, out hitInfo))
{
Debug.DrawLine(hit.origin, hitInfo.point, Color.red);
Debug.Log(hitInfo.point);
}
Debug.DrawLine(transform.position, lookAtPosition, Color.green);
rayproblem.png
(261.9 kB)
Comment
Your answer
Follow this Question
Related Questions
Vertical auto-aim with raycasts 1 Answer
Detemine wich side of a cube was hit 1 Answer
rayCastHit question 1 Answer
RaycastHit Collider Question 1 Answer