- Home /
Question by
JackieTilley92 · Jan 22, 2016 at 04:35 PM ·
2drotationjointanchorfixedjoint
Rotation of object is effecting my FixedJoint2D anchoring point.
Hi, I have a problem with anchoring a Fixed point on a 2D object. I am using this fixed point to make a circle "sticky" and I have no problem doing so IF the object that will stick to it is at a rotation of (0,0,0)
HOWEVER, if I rotate the object that will stick to it on the z axis, the anchoring point changes to a random point on the edge of the circle. I want to find out what is causing this since I do not use the objects rotation in any of my calculations for the anchoring point.
Can anybody help me? I am relatively new to unity.
void OnCollisionEnter2D(Collision2D c)
{
if (hit != true)
{
Debug.Log("STICK");
FixedJoint2D joint = gameObject.AddComponent<FixedJoint2D>();
joint.connectedBody = c.rigidbody;
//calculate new anchor point
float newX = gameObject.transform.position.x - c.gameObject.transform.position.x;
float newY = gameObject.transform.position.y - c.gameObject.transform.position.y;
Vector3 v = new Vector3();
v.x = newX;
v.y = newY;
v.z = 0;
joint.connectedAnchor = v;
}
}
Comment