- Home /
Raycasting with Rotation of Camera
I have a Line Renderer and i check if one Line of the renderer Collides with Something. I use Raycasting to check for Collision i raycast from every Vector3 of line renderer to the next one. The Problem is that the Rotation of the player isnt in my calculation, so the raycasting only takes place on one single line undependet from the players direction. I dont know how to fix that problem, here is a picture of the problem. How you can see the Rays are facing in the right direction but they are not have the right start points, it should look like in picture one, wathever direction the player is loking.
for (int n = 0; n < 200; n++) {
vectors[n].x = n / 10.0F;
vectors[n].y = cam.transform.position.y + 2*((vectors[n].x - 2) * (vectors[n].x - 2)) + 4;
vectors[n].z = 0;
if (n >= raycastAccuracy) {
if (Physics.Raycast(new Vector3(cam.transform.position.x, 0, cam.transform.position.z) + vectors[n - raycastAccuracy], (vectors[n - raycastAccuracy] - vectors[n] + new Vector3(cam.transform.forward.x, 0, cam.transform.forward.z)).normalized, out hit, Vector3.Distance(vectors[n - raycastAccuracy], vectors[n]))) {
if (!hit.transform.CompareTag("RemotePlayer")) {
Debug.Log(hit.transform.name);
xMax = hit.point.x;
break;
}
}
}
}
It is not clear to me what the problem is. I don't know what the red arrow is indicating.
The red Arrow show the direction the camera is facing at
Your answer
Follow this Question
Related Questions
Raycast hitting objects to the left of my player 1 Answer
Multiple Cars not working 1 Answer
What's wrong with my RaycastHit2D? 1 Answer
Another Raycast Issue. 0 Answers
How can I have separate floats for each gameobject? 1 Answer