Playing around with Rigidbody2d I noticed there aren't options to freeze rotation/position like there are on a Rigidbody. I'm not too familiar with what's possible with Box2d so I don't know if this will eventually make it into Unity's implementation of it, but I'm wondering if there are any workarounds to setting up constraints on a Rigidbody2d (aside from not using it).
I was wondering this too whilst starting to play around with the 2d widgets this morning, I suspect the new way of achieving this is to attach a sliderjoint2d but I don't have a working example yet. You can stop rotation by selecting 'Fixed Angle' in the rigid body 2d component.
Noticed the same thing and wondered myself... I'm hoping it will be added, but like you said, fixed angle covers the rotation... as far as position locking is concerned I suppose the only way right now would be to lock it via code in an update function or something.
Unfortunately yes, Box2D only provides constraints in the form of joints. It would be possible for us to internally add a SliderJoint2D for the X and/or Y axis to offer such a constraint but this wasn't something we were considering for the 4.3 release. I'm not sure if we'd really want to do that in the future but if there was a significant need for it then maybe so. Hope this helps.
I'm looking for a solution to constraint a rigidbody2d but I'm a bit lost. Can someone please expand on the SliderJoint2D solution mentioned here?
It's as simple as it sounds. Use a slider joint to lock the rigidbody2d on a single axis. http://docs.unity3d.com/Documentation/Components/class-SliderJoint2D.html
Here is a script you can pop on any object and easily choose which axis to lock. Code (CSharp): using UnityEngine; using System.Collections; enum AxisDirection { x, y } [RequireComponent (typeof (SliderJoint2D))] public class AxisLock : MonoBehaviour { [SerializeField] AxisDirection lockAxis; void Awake () { SliderJoint2D slider = GetComponent<SliderJoint2D>(); slider.connectedAnchor = new Vector2(transform.position.x, transform.position.y); slider.collideConnected = true; if (lockAxis == AxisDirection.x) { slider.angle = 90; } else { slider.angle = 0; } } }