I’m trying to draw a ray to the mouse position from my player but it is acting very strange. Firstly the whole ray isn’t even where the mouse is but if I use Debug.DrawLine instead of Debug.DrawRay then it works. Here is a screen shot of the first problem. The second problem is whenever I move the player the end point of the line also moves when it shouldn’t because the mouse isn’t actually moving, just the player. Here is the code:
var mouseWorldPosition;
var raycastHit : RaycastHit;
function Update(){
DestroyTile();
}
function DestroyTile(){
var mouseWorldPosition : Vector3 = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, 15));
Debug.DrawRay(transform.position, mouseWorldPosition, Color.red);
}
Can someone please tell me why it’s acting so strangly?
Thanks.