Question by
adamarend11 · Mar 06, 2021 at 10:08 AM ·
physics2donmousedrag
Im trying to grab 2D objects, with an offset and swing them around but nothings working heres my code :
Vector3 offset;
Vector3 MousePos;
private void Update()
{
MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
private void OnMouseDown()
{
offset = transform.position - MousePos;
}
void OnMouseDrag()
{
GetComponent<Rigidbody2D>().position = MousePos.normalized + offset.normalized;
}
Comment
Your answer
Follow this Question
Related Questions
hysics2D.GetIgnoreCollision not persisting,physics2d.ignorecollisions not persisting 0 Answers
OnMouseDown/Drag/ets is not being called in WebGL build 0 Answers
Swinging a bat to hit a falling ball 0 Answers
how to find velocity magnitude relative to transform.right. 2D 2 Answers
Constant Velocity? 2 Answers