- Home /
This question was
closed Aug 03, 2014 at 07:43 AM by
Firedan1176 for the following reason:
I already solved my problem.
Question by
Firedan1176 · Jul 21, 2014 at 02:28 AM ·
cameraraycastrayscreenpointtoray
Follow mouse cursor (with Y = 0)?
How can I use the ScreenPointToRay to get my GameObject to be aligned to the floor (using only x and z)? Instead of using a distance variable to do this:
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
mousePos = ray.origin + (ray.direction * markerDistance);
playerTarget.transform.position = mousePos;
How can I have it instead of spinning around in a "spherical" pattern, how can I get the y axis to always be 0, but the object will still be in the correct location?
Comment
Answer by Bojidar · Jul 21, 2014 at 03:01 PM
Put a Plane (maybe without a mesh renderer) for the floor, and set its layer to "floor". Then use this code:
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Physics.Raycast(ray.origin, ray.direction,
80, 1 << 10 /*change 10 with the number of the floor layer*/);