Question by
Lazybones94 · May 30, 2016 at 08:27 PM ·
hit.pointphysics2d.raycast
Strange Physics2D.Raycast behaviour
I have a following code in Update():
if (Input.GetMouseButton(0))
{
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), rotater.transform.position, 50, joystickLayerMask);
Debug.DrawLine(Camera.main.ScreenToWorldPoint(Input.mousePosition), rotater.transform.position);
if (hit != null && hit.transform != null && hit.transform.gameObject.tag == "joystick")
{
joystickCursor.transform.position = hit.point;
Debug.DrawLine(Camera.main.ScreenToWorldPoint(Input.mousePosition), hit.point, Color.green);
return;
}
}
rotater is an empty object inside of a silver cirlce(right in the center), that is supposed to rotate facing mousePosition.
But here's the output:
Problem: while mouse cursor is inside the silver circle, everything is ok. But I want everything to work even when cursor is outside the silver circle, though the little white circle should stay inside of the silver circle. In the case of a screenshot above, white circle should be on the position of white ray entering the silver circle. Why is the green ray even behaving such way? It must be right on the white ray!
234534.png
(157.6 kB)
Comment