# Rigidbody2d position constraints X+Y

Hey,

I checked google for this, found some ideas how to do this, but it didn’t work.

We have HingeJoint2D that rotate a stick, when something small with low Mass hit it - it rotate on the spot - just as we want.
But when something with higher Mass hit it - it rotate And moves.
We want it to only rotate on the spot, even if it got hit by something with higher mass.
If we change the stick mass - the something with higher mass rotate it on the spot, but the something with lower mass doesn’t rotate it.
If we use Rigidbody2d.position or Rigidbody2d.MovePosition to make sure it’s still on a fixed position, every FixedUpdate, it helps a little, but still moves.

Any ideas how can we make sure that the Stick will always only rotate on the spot when hit by other objects?

Thanks

While there bound to be a 2D joint which can be defined to be anchored to some fixed position. If such a behaviour acutally does not exist in a 2D joint than it can be simulated by a 3D joint. However its a bit ugly

I know that there are 3D joints that work in such a manner that they can be placed in a fixed position. If you make invisible colliders for those joints, and then attach or bind your 2D sprites or whatever you are using acording to the position of the simulated 3D joints. then it could work no?

Sounds too complicated to implement - We’ll have to check collision on 2d, then transfer the hits to 3d, then return the outcome to 2d

nope I say have a 3D invisible simulation that will represent the location of the 2D elements. Like what we used to do with world GUI before the World Canvas of UI 4.6 came out

Are you sure you didn’t find any way for the hinge joint to remain static. seems to me that something else is moving it. maybe somehow connect it to another joint that is immovable? cause by definition joints connected to each other will never seperate no matter what.

Nope.
It’s a rigidbody2d with hingejoint that is connected to a kinematic rigidbody2d

Know that Rigidbody2D constraints for X/Y position and Z rotation are coming very soon in Unity 5.

We already offer a Z rotation constraint that is named ‘FixedAngle’ but this will change soon and appear the same as 3D physics in a separate constraints section. Don’t worry though; the script-updater will automatically update your scripts for you that refer to ‘FixedAngle’.

@MelvMay , Good to know, but I’m looking for a solution that’ll work now
I can’t find a way to Make sure that only position on X+Y will be fixed, while the Z rotation will remain free.
So FixedAngle doesn’t help in this case…

FIXED!
Added to kinematic rigidbody2d colliders in the same shapes and positions as the stick.
Used Physics2D.IgnoreCollision on the colliders of the kinematic and the stick.
On FixedUpdate set the kinematic to use the stick rotation.
And it works

1 Like