Hi !
I want to rotate an object around another using physics in 2D (I want to keep the velocity so the object can throw himself like Spiderman !). The problem is that it goes crazy when I try to use the cross product and I don’t really know why. Can someone explain to me why it’s behaving like that ? Thanks !
Code and stuff :
Have you tried checking the values you get?
Vector3 dir = (target.transform.position - transform.position).normalized;
cross = Vector3.Cross(dir, Vector3.forward);
Debug.DrawRay(transform.position, cross * speed);
rb2d.AddForce(cross * speed);
I’d guess you have to add some force to keep your object in close range. Basicly, you should add the force of your rope pulling your object towards the hook point. The farther away from it you move the stronger the force, depending on the flexibility of your rope.
Hi, thanks for the answer it inspired me !
I found out that the x value of the velocity wasn’t 0 when it should have been. So here’s my changes :
//Wrong way
rb2d.AddForce(cross * speed);
//"Correct" way
rb2d.velocity = cross * speed;