- Home /
How can I change SpringJoint2D's anchor points in script?
LAST EDIT: Problem pinpointed, but not solved. When I rotate the body the wheels rotate with it, BUT the springJoint2D anchorpoints are hardcoded... Meaning the wheels will get back to original position due to physics. Any workarounds?
EDIT: It is an object with rigidbody2D component and 6 springjoint2D's attached to it (3 per wheel)
Still no answers... bump bump
Wondering if there is a way to do this with GetComponents
first you have to use Rotate $$anonymous$$ethod to do that.
transform.Rotate(Vector3.up * Time.deltaTime);
or along the space axis
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
If you want to assign a particular angle you have to use for example:
transform.rotation = Quaternion.Euler(0, 180, 0);
or:
transform.eulerAngles = new Vector3(0, 180, 0);
for physics problem i don't know
Yes i know how to rotate it :/ the problem is the physics since it has to be instant 180 degree rotation...
I tried this:
bike.rigidbody2D.is$$anonymous$$inematic = true;
wheel.rigidbody2D.is$$anonymous$$inematic = true;
wheel2.rigidbody2D.is$$anonymous$$inematic = true;
bike.transform.Rotate(Vector3(0,1,0), 180);
bike.rigidbody2D.is$$anonymous$$inematic = false;
wheel.rigidbody2D.is$$anonymous$$inematic = false;
wheel2.rigidbody2D.is$$anonymous$$inematic = false;
this way it's a little better but still the wheels collide with eachother when rotating and bounce around turning the whole bike...
Yes they are, but it's like they won't rotate in y-axis... AT ALL
Answer by GTX Titan · Feb 03, 2014 at 11:07 AM
Ok nevermind this did the trick :)
var joints = GetComponents(SpringJoint2D);
for(var joint: SpringJoint2D in joints){
var temp = joint.anchor;
joint.anchor = Vector2(-temp.x,temp.y);
}