I am trying to raycast a “cursor” object on to the terrain below from the camera using the mouse’s position, but for some reason the object I am raycasting is flying towards the mouse and not staying on the ground.
Here is my code:
public Camera MainCam;
void Update () {
//pointCursor
RaycastHit hit;
Ray ray = MainCam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit)) {
transform.position = hit.point;
}
}
UPDATE: FIXED, just needed to add a layermask