[ODE] Avatar control vs gravity

Andrzej Szombierski qq at kuku.eu.org
Wed Nov 17 21:43:02 MST 2004


On Wed, 17 Nov 2004, Gary Haussmann wrote:

> 
> I once tried to solve the same problem; getting an avatar to walk around on 
> hills and valleys consistantly with gravity.  My final solution was a bit of 
> a hack, but it seemed to work OK.

I have once implemented something similar. I've managed to extract this 
piece of code:

==CUT==

// don't touch the contact if the normal doesn't point up "well enough"
if(ct.geom.normal[2] > 0.5){

	const dReal * R = dBodyGetRotation(/* the player body */);

	// fdir1 points towards the player's X axis
	ct.fdir1[0] = R[0];
	ct.fdir1[1] = R[4];
	ct.fdir1[2] = R[8];

	// 'velocity' is a variable controlled by arrow keys/whatever
	ct.surface.motion1 = ct.geom.normal[2] * velocity;
	ct.surface.mode |=  dContactFDir1 | dContactMotion1;

	ct.surface.mu2 = ct.surface.mu;
	ct.surface.mu = 20; // parameter like FMax in joint motors
	
	// disable Approx1 for friction direction 1
	// (doesn't matter if it wasn't set earlier)
	ct.surface.mode &= ~dContactApprox1_1;
}

==CUT==

It works quite well, it allows to control the player relatively to the 
"ground" (important if he is standing on a moving object), and keeps him 
from changing direction while falling (this "feature", although realistic, 
can be quite annoying :)

-- 
:: Andrzej Szombierski :: qq at kuku.eu.org :: http://kuku.eu.org ::
:: anszom at bezkitu.com  :: radio bez kitu :: http://bezkitu.com ::



More information about the ODE mailing list