[ODE] Rotation troubles

Ruud van Gaal ruud at marketgraph.nl
Thu Dec 25 23:40:50 MST 2003


...
> As an example of what we're trying to accomplish with this, 
> imagine an 
> ODE/AI controlled enemy helicopter. We want it to 'do its 
> best' to keep 
> the gun (=forward direction) aligned with the player, and the 
> having a 
> limited rotational power to accomplish this with. This 
> implies that the 
> target position will change continously.

I always like to take the blunt approach, trying to reason from a human
point of view. In this case, you want to target the enemy target (or
whatever target), and rotate there but not overcook it if you're already
rotating fast.

Make a sort of damper system:
- the enemy helicopter offset becomes T: T=enemyPos-playerPos
- the current direction is P. P is just the gunDirection
- Normalize T. P is already normalized.
- Take a dot product d=T dot P which tells you how close you are to your
ultimate target
- If d~0, it's good enough, exit here
- Otherwise take a cross between T & P to determine which side to rotate to
(in body coordinates)
- Use a spring/damper formula to determine the response:
  Torque=(1-d)*k + playerYawVel*c_damper
  Where k is the spring constant, pulling the heli towards the desired
direction,
  and c_damper is a damper constant that takes into account any current
rotation.
  1-d will get close to 0 when the target is matched.
- Experiment with k and c_damper.

> So far, I can easily get the helicopter to turn towards the 
> player, but 
> it overshoots. I tried to calculate the rotation of the 
> helicopter in 1 
> second,

This would work much better if you determine the overshoot per physics step.
So not 1 second, but your time period.

I use a system similar as above in a helicam tracking a car. SMD systems
(spring-mass-damper) have well-defined properties if you want to calculate
c_damper values instead of experimenting (for under-, over- and perfect
damping).

Hope that helps,
Ruud


More information about the ODE mailing list