Tips and Tricks

From ODE Wiki
Jump to: navigation, search

This article is known to contain outdated information. If you know of correct information, please edit this article! Thank you.

Poor collision quality/excessive fallthrough with trimesh-box collisions?

Try increasing the maximum number of contacts. 128 seems to work well.

I find that a much smaller number of contacts between each body and the collisions is sufficient; I use on the order of 10 and seldom actually need that many (per geom pair).

Want to recover a vehicle that's flipped upside down, onto a race track or similar?

There are three things that can kill you:

  • 1. stored velocities (angular or linear) can jerk you around
  • 2. joint constraints can induce explosive forces if violated
  • 3. penetrations at the "restoration" point can induce significant energy

To solve 1, you simply dBodySetLinearVelocity?() and dBodySetAngularVelocity?() to zero.

To solve 2, you have to use a "blueprint" of what bodies goes where, in what orientations, and with what joints. To create your object, first create the bodies, attach the geoms, and then call AssembleFromBlueprint?(), which will move/orient the bodies, and then re-set joint constraints (remembering the low/high ordering problem), and then attach the joints. When you want to re-set the vehicle, detach all bodies from their joints (without destroying the joints), and call AssembleFromBlueprint?() again. It certainly helps if your Assemble() function takes an optional global translation/orientation to apply after all the local offsets/rotations :-) Note that IF your joints and bodies are all still sane, and you kill the energy (as in 1), then it "ought" to work to simply offset and translate all the bodies. You have to make sure you first rotate all the bodies AROUND THE CENTER OF THE VEHICLE, and then translate to where you want to go -- if you just set the rotation of each body, when the car is upside-down, that will end up with wheels sitting on the wrong side of the body, and your joints will make you very unhappy.

To solve 3, I ray-cast down from 5 meters above the intended recovery point, and find the surface normal and distance. Then I lift the vehicle up such that it won't penetrate the assumed plane described by that normal (using bounding-box test). Then I lift it up an extra two meters, just for paranoia, which leads to a nice drop straight onto the recovery position.

All joints fall apart or behave strangely?

Attach the joint before setting Anchors and Axes - otherwise they won't work as expected.

How to make a ragdoll follow a pre-determined animation

This part could warrant its own HOWTO. It is known to be difficult, however --Jlargentaye 04:51, 19 April 2006 (PDT)

How to turn an animation into dynamics forces:

I'm assuming a rigid skeleton with ball joints, but you can generalize to any kind of joint that your animation uses:

For each frame, pose your animation skeleton the way the animation wants it for the NEXT frame in time.

Then, for each body in your dynamics skeleton, measure the angle relative to its parent, and compare to the animation skeleton. This gives an angle error in parent-relative space for each bone.

Now, calculate the torque necessary to move the body to the desired angle in the next timestep (or in some amount of future time, of you want a more dampened fit). Optionally apply maximum joint torque constraints. Apply this torque to the body. Step the world. Yay, you're done!

For position constraints, substitute "movement" and "force" for "angle" and "torque".

You should also keep an error accumulator, and add in some multiplied factor of that error to your force, so that you will compensate for being off in a specific direction for many steps. You can implement this as a leaky integrator of angle error, or as an accumulator/time-based "spring".

Contact with the ground (and movement, in general) will be maintained because of physics; there will be friction between ground contacts (feet) and the ground. Balance will be maintained by your animator creating a good animation... You can also cheat a little bit; if you apply torque towards the root joint (typically, your pelvis) compared to the world space orientation of your higher-level entity, then the integrator will compensate for any off-balance animation, basically through a force that's derived from "magic".