- Home /
help with simple pendulum simulation
Hello, I am trying to make a simple pendulum setup with Unity's physics system but I am experiencing some bizarre behaviour.
Here's my setup, I have a ball attached to an elongated capsule using a fixed joint. Then, the elongated capsule is attached to a cube using a hinge joint, finally the cube is constrained in the XY and Z axis in both translation and rotation (this is the only I found to make the cube stay fixed).
here's a screenshot to make things clearer:
and here's a video of the resulting simulation:
all wrong :( ... for some reason, the capsule and ball seem to be attached to a spring (all spring-related settings are turned off).
Surely lots of people have successfully made a 2D pendulum with Unity physics??
any help is appreciated,
D.
Answer by aldonaletto · Aug 16, 2012 at 01:38 AM
It seems that the connecting body is colliding with the cube and causing this weird behaviour. You can simply remove the cube: set the Connected Rigidbody field in the hinge joint to null, what means "connected to the world" for the physics engine. But if you really need the cube, replace the hinge joint by a fixed joint and enable rotation only in the desired cube axis: the whole pendulum will rotate around this axis.
Answer by electricsauce · Aug 16, 2012 at 01:47 AM
I tried the same thing, but with axis 1,0,0 on the capsule and it worked correctly for me. I was able to replicate your results by lower the mass of the capsule to close to 0.
Figured it out, it's because your capsule is connected to the outside of the cube. It has to be perfectly centered for it to work.
Answer by flamz · Aug 17, 2012 at 02:10 PM
Thanks for your help. I managed to get it working, somewhat, trying both solutions. However, I still get some instabilities using a very simple fixed-joint setup.
Here's how to reproduce the problem:
Create a cube
move it to (25,10,45)
add a rigid body component
turn off gravity and constrain in XYZ for both position and rotation (pin the object)
next:
Make a sphere
move it fairly far away from the cube (I use 60,0,45)
add a rigid body component
add a fixed joint and use the cube as a connected body.
run the simulation.
result: as the ball falls, it starts to swing as it should, like a pendulum. But then, when it reaches the apex of the curve, it starts to behave as though it was connected to the cube using a spring and starts to bounce around.
if you move the ball closer to the cube, everything runs fine. Or if you reduce the ball's mass, everything is fine as well, which makes me wonder what the "infinity" setting means in the "break force" property...
:(
Yeah, Unity's physics can get weird sometimes. If you're just trying to make the look of the pendulum attached to the cube you could probably parent the cube and the pendulum to an empty and attach your capsule(arm) to the world via a hinge joint like aldo suggested.
Answer by Pavan Shinde · Aug 31, 2012 at 07:04 PM
Hi, I got the simple pendulum working nicely. This is how I'm doing; create 2 spheres with some distance between them. Freeze rotation and position for a sphere, change its mass to 50 and uncheck the "Use Gravity" check-box. Put a spring joint between the spheres and make Spring value 9e+37.