[ODE] Controlling an avatar and the use of AMotors

Geoff Carlton gcarlton at iinet.net.au
Tue Nov 9 09:35:29 MST 2004


I've got a basic working system using the ccylinders and AMotor.  Its 
may not be optimal, but it works and thats been good enough so far.

I create the AMotor with user setting, axis set to standard X,Y,Z locked 
to the body (in my game +Z is up, and the character spawns standing 
upright).   Now, firstly you'll want to check your ode has a recent 
AMotor fix for user angles (posted here a while back).  To use the 
AMotor, I work out the angles myself and plug in desired velocities for 
each of the 3 axis.

Now by setting Vel on axis 3 you can control its rotation around its 
local up (ie its facing).  To calculate the Vel you have to consider 
where the character is facing and where you want it to face and consider 
the difference, and translate that into a desired velocity.  I only do 
this when the character is mostly upright, which makes the comparison 
easier (you can flatten the vectors so that z=0 before considering the 
difference).

By setting Vel on axis 1 and 2 you can add forces to try to keep it 
upright.  To do this you need to rotate the body around the shortest arc 
to get it back to upright, which is the cross product of local up and 
world up.  This needs some extra checks and scaling (e.g. if the guy is 
on his head, just pick any angle).  I look at the modified cross product 
and pull out the x and y components to plug in as axis 1 and 2 Vel.

I'm not sure whether this is what anybody else does, so I'd be curious 
to hear of alternate solutions.  In particular, it seems to have trouble 
when rotating the facing while trying to get up, it twists on the ground 
and struggles to right itself.  I got around this by not turning the 
facing unless the capsule is mostly upright (so its really only doing 
either twisting, or uprighting, never both).  Also, when I was 
experimenting I found it easier to set up the user angles and plug in 
fixed Vel values and make sure its spinning the right way before trying 
to come up with a proper set of solutions for it (e.g. plug in a fixed 
value for axis 3 and see the capsule spin its facing around - gives you 
encouragement for continuing on!).

Geoff

Patrick McColgan wrote:

> Hello
>
> I'm trying to develop a character controller in ODE, I've already gone 
> through the mailing list and read similar queries.  The recommended 
> approach for maintaining something like a vertically standing cylinder 
> is to use an amotor however I have extensively searched the mailing 
> lists and beyond this recommendation there isn't much more support for 
> the use of amotors themselves and their use in such a situation.
>
> I haven't found the ODE manual particularily clear when discussing 
> amotors either.
>
> At the minute I have implemented an amotor between a sphere and the 
> environment (i.e. nothing) and use dAmotorEuler (defining global y and 
> x axis as the first and third axis) so it automatically defines the z 
> axis as the second axis.
>
> From this it can return the relative rotations from the sphere's local 
> axis and the global axis as Euler Angles.  Is this essentially what an 
> amotor does?  Just returning the difference?  I don't find the use of 
> Euler angles particularily useful.
>
> I'd really appreciate if anyone had a more detailed approcah for the 
> application of AMotors to maintain an avatar (i.e. keeping something 
> like a cylinder upright).
>
> Thanks
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
>
>



More information about the ODE mailing list