- Home /
Rigidbody2D mouse follow
I'm trying to get a Rigidbody2D to follow my mouse and have physics responses.
In 3D I'd use Rigidbody.MovePosition, but that doesn't exist for 2D.
When I simply move the transform, I get OnTriggerEnter responses, but never get an OnTriggerExit. I believe this is because the collider is not actually moving, but instead being destroyed and rebuilt every time the transform.position is changed.
Answer by Chris_E · Nov 22, 2013 at 12:23 AM
I was able to do this by making a 2D joint with no connected body, and a script that keeps the joint object following the mouse at all times. When I do an OnMouseDown over the item I want to drag I make it the connected body on the joint, which causes it to follow the mouse. I set the connected body back to null OnMouseUp. It gives events properly, and follows the mouse, but it's not the most elegant of solutions.
Please dont make comments as answers. I'm searching something like your question