Raycast pointing in the wrong direction
I have a script where there is a ray that goes from the camera to where the cursor is so that and object will follow the mouse but I am having a problem where it is accurate when the mouse is moving, but as soon as the mouse stops moving the ray moves around 5 units from where it should be.
public class CameraMovementRay : MonoBehaviour { public Camera playerCam; Ray cursorRay; Vector3 playerPos; public RaycastHit cursorHit; public LayerMask clickPlain; public bool cursorHittingFloor; void Update() { cursorRay = playerCam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(cursorRay, out cursorHit, 100f, clickPlain)) { print(cursorHit.point); Debug.DrawLine(cursorRay.origin, cursorHit.point, Color.red); cursorHittingFloor = true; } else { Debug.LogError("Not on the grund"); cursorHittingFloor = false; } }
Your answer
![](https://koobas.hobune.stream/wayback/20220612233714im_/https://answers.unity.com/themes/thub/images/avi.jpg)