For some reason, a rigidbody attached to another rigidbody with a Hinge Joint 2D is spinning randomly. Whenever the main rigidbody moves, the attached object spins in a full circle. How can I fix this? Literally though, even if there is a collider that should collide with it, it still spins in a full circle multiple times around for no reason. Shouldn’t the angle limits make it so every time it reaches its limit it springs back to its original position?
Have you tried playing around with the maximum motor force, use limits, and use motor variables on the attached object that is spinning?
I’ve been playing around with hinge joints and I just can’t get them to work, they are somewhat okay with limits and motor turned off so they can just spin freely but they still stretch like crazy when dragged in contact with another collider or even just when hanging off a parent body that’s rotating at a moderate rate. I’ve used JBox2d before and Farseer under unity and normally these problems are related to trying to use too small or too large a scale but in unity I can’t find any reference to what the right scale to use is. I’m working under the assumption that 1 unit = 1 metre but I’ve tried going up and down on that by a factor of about 10 without much success.
As for the OP when I’ve tired to use limits that is exactly the behaviour I’ve seen, It seems when it hits its limit rather than stopping or bouncing back it just does a complete spin. Very odd, is it a bug, are these all scale issues and I should be using a much different scale than I’m using 100 units = 1 metre? I dunno, its very frustrating and I’m on the verge of just going back to using Farseer for unity which seems way better implemented even if it is probably going to be a little slower.
I don’t understand why the physics is implemented in such a limited way, especially when there are products on the asset store (both free and paid) that seem to do a better job. There are a couple of nice things about the built in physics but the lack of joint types (no visual editing for joints unless I’m missing something, which is just astonishing), freaky behaviour and general lack of robustness just leaves me wondering why they bothered.
Its a shame because mostly I find unity to be fantastic.
(Think I’ve solved my problem here see below).
Right, having read through a few other posts here I think I’ve figured out my problem which may also be the problem the OP has. I had the connected parts as children of the main part. This seems to cause all sorts of bugs such as I described in my post, When I moved them all out to be children of a passive (non physics object) just to keep them organised it suddenly started working correctly, including the joint limits! Haraah. Seriously there needs to be a tutorial regarding the 2d physics because issues like this cause a lot of headaches. Still think there are issues with the 2d physics but at least what’s there does actually work when setup correctly ![]()
Edit - And just to add weirdness I just put the wing objects which are just sprite renderers with no physics attached back as children of the main ridgidBody2d object so they move with it and the bugs came straight back! Why having a couple of sprite renderers as children should cause this bug I have no idea. I solved it by putting an empty gameobject as a child of the body object then put the wings in the child object… Works fine… Crazy.
Edit2 Scratch the above. The problem is actually related to the fact the wings are animated (with rotations) even though I’ve tried it with animated physics on and off, which doesn’t appear to do anything. Le-sigh.
Thank you WeirdWizard, I’ve had the same problems with my “rope” of sprites stretching and the uppermost one rotating unnecessarily. I will now go try and not make copies of the top one to form the bottom ones - that must be forming children of the top object! ![]()