Is there a way to lock the object in the x-axis in Unity 4.3 2D?
I have a 2D sprite with a rigidbody2D attached to it.
2 Answers
2You can constrain which axis it can’t move in, in the rigid body.
I know this is an old question, but Google didn’t reveal the right answer anywhere.
For RigidBody2D you can constrain in one axis by attaching a SliderJoint2D
But that's not for 2D. I checked the documentation, but I don't think that exists in rigidbody2D. :/ Thanks though :>
– ccgbagnetYeah, I don't see anything like that for 2d. You could set the position every frame: void Update() { Vector3 position = transform.position; position.x = 0; transform.position = position; }
– SpinnernicholasThat worked! Thank you so much!
– ccgbagnetTo be honest, this is suboptimal as the position can be changed inside the frame and thus can cause glitches when its set back to the original position. The only thing i found to be working is "set kinematic" to prevent the object from recieving forces by other objects. This though prevents collision detection
– alexpf