- Home /
2D platform anchored in center, rotate only
Are there any joints or special physic objects I can use to create a platform that acts like it has a peg through the center, so it is only allowed to rotate on the Z axis, but cannot move (location)?
I tried just not allowing the position to change with this script:
Vector3 StartPos;
void Start () {
StartPos = transform.position;
}
void Update () {
transform.position = StartPos;
}
However, that throws off the physics -- the way it interacts with the rest of the world and other objects. For example, if another object lands in the center of this object, it will slowly "pass through" the object, which just looks wrong/impossible. I imagine it is because the physics engine is actually trying to move my "fixed" object down, due to the weight of the other object landing on it... but then I'm forcing it back up, but in a way the physics engine doesn't recalculate for.
Hopefully I'm just missing something simple.
Go to the Constraints section of the Rigidbody and freeze the x, y, and z position and the x and z rotation. Does this do the job?
That's what I thought also, but I think that is only for 3D, don't see those properties for Rigidbody2D.
Answer by Pyrian · Apr 26, 2014 at 04:38 PM
Sounds like a HingeJoint2D to me.
Thanks, I guess I didn't even look at that because of the name. Teaches me to look beyond the name, as the docs clearly state: "The hinge joint's name implies something like a door hinge (and it can certainly be used to implement that) but it refers more generally to anything that rotates around a particular point."
I know, right? The only reason I know it works like that is because I wanted something anchored at one end. Glad I could help. :)
Your answer
Follow this Question
Related Questions
Unity 2D Bend Sprites between HingeJoint2D 1 Answer
HingeJoint2D.GetReactionForce not working 1 Answer
how to make a 2d character three-dimensional? 1 Answer
2D random shooting problem with velocity, 0 Answers
Dash towards cursor 1 Answer