- Home /
Ray Over Mouse
Why does unity put my ray over the mouse position instead of it being exactly on it?
var mouseWorldPosition : Vector3 = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, 15));
Debug.DrawRay(transform.position, mouseWorldPosition, Color.red);
The ray is always a couple of pixels above where the actual mouse is. I don't understand why it's this way can someone help me out?
Thanks.
I'm not sure what you're going for with that code snippet. ScreenToWorldPoint
returns a position, not a direction, but Debug.DrawRay
's second parameter takes a direction. Do you want the ray to start at the mouse position, end at the mouse position, or be along the line through the viewpoint and the mouse position (and hence appear as a point)? And what's the object whose transform.position
you're using?
I'm using my player's transform.position. I want it to start at my player and end at the mouse position. Here is a pic it's hard to explain: http://i.imgur.com/arz5y.png
Answer by sneftel · Aug 12, 2011 at 07:11 PM
Use Debug.DrawLine
if you want a line from one point to another.
Your answer
Follow this Question
Related Questions
Rotation of Object on single axis in direction of the mouse position 0 Answers
Checking if object stopped being hit by Raycast while overlapping another object of the same type. 0 Answers
Input.mousePosition Dead Zone - See gameplay 0 Answers
How to find out which object is under a specific pixel 1 Answer