# How to constrain an object to a compound child?

I have a rigid-body vehicle made up of parts with compound collision enabled, so that the parts don't collide with each-other (for optimization purposes).

I'd like to constrain the rear wheel to a bit that rotates according to the whims of the player, but for some reason this doesn't work.

Here's an example .blend:

I'd like to get the Rear Wheel object to follow the Tail object when the player presses ← Left arrow and → Right arrow, while still rotating freely around its local Z axis.

I would've expected changing Rear Wheel's constraint target from Body to Tail to accomplish exactly this, however the constraint then doesn't work at all.

• The back wheel is hinged to the back fin, which moves from side to side while the wheel itself can only roll forward, so it can't really stay with the fin. When I changed the constraint to a ball it seemed to work more like you want. Remember, a hinge constraint only moves in one direction. A ball constraint has more flexibility. – Anthony Forwood Jun 2 '16 at 21:01
• @AnthonyForwood A ball constraint allows the object to rotate in any direction, which won't work very well for a wheel. The idea is to constrain the wheel to the back fin in such a way so that "forward" is in line with the back fin, whatever orientation it may be in. – gandalf3 Jun 2 '16 at 21:39
• Can't you still constrain it to just two axes? Maybe I shouldn't have spoken. – Anthony Forwood Jun 2 '16 at 21:58
• @AnthonyForwood Not sure what you mean..? – gandalf3 Jun 2 '16 at 23:42
• Never mind... I don't know what I'm talking about. :-) – Anthony Forwood Jun 3 '16 at 2:13

The issue can be clearly seen if you put it into physics visualization mode: The physics engine never notices that the tail rotates!

Now, why is this? This is because compound objects don't necessarily update the physics mesh other than at game start. I'm not entirely sure of all the details, but you this issue with parenting and physics not always doing what you expect comes up quite regularly.

The reason why changing the constraint to the tail makes the joint fail entirely is that when the parent has 'compound' enabled, the child's mesh is appended to the parent's mesh, and a physics mesh is generated for the parent+child object. This physics object is assigned to the parent, and the child is ignored by the physics engine entirely.

As to the solution, There are two ways:

1) The first is to disable the parent's "compound" option, preventing the child from being ignored by the physics engine. Then the two objects collide, so one of them will have to be set to ghost to prevent the perpetual collision sending the parent and child flying.

2) The second method is to attach the child to the parent not by parenting, but with a second rigid body joint. The issue with this is that, if you wish to steer the tail, you have to create that constraint from python so you can use the rather poorly documented constraint.setParem() method to control it. This is the method I use whenever I simulate vehicles, such as this n-wheel steer thing: https://dl.dropboxusercontent.com/u/17630723/Blends/Rover-packed.blend (I'm actually quite proud of the math controlling that vehicle. It calculates the wheel velocities and angles for a wheeled vehicle to move along a certain path with minimal wheel slip)

• Thanks, that makes a lot of sense now. I still want the tail to collide with objects that are not part of the vehicle, so I set up a collision group such that none of the vehicle parts collide with each other, but still collide with everything else. This works well, but strangely the constraint now behaves "weak". It acts like it wants to be in the right place, but is easily pushed out of the way. Here's a .blend with the weak constraint. BTW, for me your demo rover falls through the floor when the game starts (2.77) – gandalf3 Jun 4 '16 at 3:45
• Blend file fixed – sdfgeoff Jun 12 '16 at 4:28