ODE and AI

Hi all, once again :slight_smile:

I’m still struggling with my (I thought to be simple) 3D turn-to-face-something-gradually “AI”.

I’m now using ODE to simulate the actor physically. I know how to apply torque to it to make it turn, and how to get the orientation quat to apply to the model.

What I now try to achieve is that the actor uses torque to turn to a target (so it should not “cheat” by directly setting its Quat, it should only apply forces/torque like a player would via joystick input or similar).

It kinda works already, but it still has glitches. Maybe you can help me find the issues…

The demo script can be loaded from: www.atlas.uni-wuppertal.de/~muenchen/oderottest.tgz

after launch, you have to zoom out a bit (mouse wheel) to see the actor, and rotate the cam a bit (right mouse button).

Now, the very first thing I don’t quite success in implementing is the extrapolation of the actor’s orientation; what I mean with this is, taking the current angular velocity of the actor, and its current orientation (Quat or its “forward” vector), determine the orientation in some point in the (very near) future.

This is visualized by the white line in the demo script. Press ‘m’ to set a new target, and watch the actor turn to face it - the white line should always point in a direction relative to the object that resembles its current rotation (angular vel). But that does not fit always :confused: and because I base the applied torque and the damping of the rotation on the angle between the extrapolated direction and the target direction, this is crucial for my simlation…

Can someone help me there? :slight_smile:

You seem to be going through a lot of complication to achieve what you’re trying to achieve. Here’s how i’d do things : take a dummy nodepath, put it in the same position as the ship, have it “lookAt” your target, get its Hpr, and compare it to your ship’s Hpr, this should be enough to know what torques to apply so that the ship rotates towards the right orientation.

To be honest, i don’t really understand what this “extrapolation of the actor’s orientation” is needed for.

Not related, but your CamHandler.py file is a symbolic link, and it takes some commenting out before your code runs, as it is now.

Hmm, do you by “extrapolation” mean “determine how to apply torque in such a way that actor won’t rotate past the goal due to the inertia”?

Well, not quite, because the ship at that moment may already have an angular velocity in some completely different direction (or, more precise, around some other axis). It’s no problem to get the axis to rotate around to face the target, and the angle around that axis; I don’t need to use lookAt for that (cross products suffice!)

Yeah, kinda. I need to apply the torque to rotate towards the target, but I also need to know when to “brake”. For that, I extrapolate the rotation my actor has a bit into the future, and if it would rotate past the goal, I “brake”. To cancel out any unwanted inertia (see top of this reply), I always damp the rotation a bit, additionally.

Now, the problem is, all this only works for something like 90% :slight_smile:

Oh, good catch, thanks!