- Home /
Mouse follow collider in a 2D game
In my game I have a code thath allows me to drag a specific block around with the mouse as long as i hold the mouse button down my problem now is thath the block doesnt collide withother blocks while draging anyone has an idea on how to solve that heres the code im using:
void OnMouseDrag()
{
Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,(transform.position.z-Camera.main.transform.position.z)));
point.z = transform.position.z;
transform.position = point;
}
Taff Question. First: if you translate a GameObject by modify his Position neither collision nor any other Physics will work. $$anonymous$$y best guess to solve your problem is, to make something with [Hinge Joint].[1]
[1]: http://docs.unity3d.com/$$anonymous$$anual/class-HingeJoint.html
Your answer
Follow this Question
Related Questions
Collision problem 0 Answers
2D box colliders not touching but are colliding, how to fix? 0 Answers
Weapon System with collide detection (Helps with script pls)!!! 0 Answers
Collision vs trigger 1 Answer
Modular Room System Similar to Mega Man 0 Answers