# moving over terrain

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to move over my terrain realistically. I used the normal of the ground to slow my movement up a hill and speed my movement down the hill. However if you turn on the hill you go faster because your speed is dependant on your heading and the normal of the ground. This allows you to go quickly up steap hills. How do most games deal with movement over terrain. I have tried to splitting up my heading vector and doing some calculations then getting resultants and stuff but i cant get it working right. i can find my correct position without any problems. i suppose i could just label certain vertices as unpassable but that would truly suck. Thankyou

##### Share on other sites
You need to find the component of your movement vector of motion along the axis of your 'hill'. Then multiply the magnitude of that vector against a coefficient based on the slope of the hill. I'd like to go into more detail but I'm at work and don't have time to get into the maths (which I'm not very good at anyway).

So let me just say you were right before, you need to split your vector so you have the velocity just in the direction of the hill's slope, alter it, and then reinsert it.

##### Share on other sites
im trying to do that. I guess i am making a mistake in the code. Thankyou.

##### Share on other sites
OK, here's some code, just pulled straight from my project. Hopefully it's fairly readable. This code does not slow or speed depending on uphill or down, but it does adjust the requested velocity to take slope into account, and caps the final velocity, so bots don't race up or down hills.

here's the ugly:

        //  OK, using the vCPU, what is wanted here?        //	note: the scaling is before the squaring, to reduce errors        dx = iScale_Word_Vectors * All_Actors .Brain.Get_Output (IO_Move_x);        dy = iScale_Word_Vectors * All_Actors .Brain.Get_Output (IO_Move_y);        dz = iScale_Word_Vectors * All_Actors .Brain.Get_Output (IO_Move_z);        //  Now (sort of) rotate to match the terrain layer        //  Note: I'm using the approximation that		//	length(1, 1*dy/dx)= 1 + |dy/dx|/2        dx /= 1.0f + 0.5f * fabs (dydx);        dz /= 1.0f + 0.5f * fabs (dydz);        dy += dx * dydx + dz * dydz;		//  make sure we have not exceeded our velocity limit        il = dx*dx + dy*dy + dz*dz;        if (il > 1.0f)            il = All_Actors .Speed / sqrt (il);        else il = All_Actors .Speed;            		//	Now actually move the cg a bit toward the target        All_Actors .Skeleton.cg.Set_Target_Rel (dx * il, dy*il, dz*il);

##### Share on other sites
thanks but i managed to get it sorted already.

##### Share on other sites
do it simply. just find the difference of height between current step and previous step, and ajust speed accordinly. If previous speed is s0 and current speed is s1, previous height is h0 and current is h1, then assuming there's no engine and no drag, you have equation
s0^2 /2+h0*g = s1^2 /2+h1*g
(that's just energy conservation)

and
s1=sqrt(s0^2+2*(h0*g-h1*g))
where g is gravity.

s1 should be then affected by drag force and engine force, as usual.

It's more accurate than to use slope.

[Edited by - Dmytry on April 2, 2005 10:47:09 AM]

##### Share on other sites
Dmytry and lonestock.

Maybe i am misunderstanding your code but it seams as thought you could go up steep hills if you face diagonally along the hill.

If you are only considering the change in height,
change in height is max if you face the steep hill.
turn roughly 45 degrees and your change in height is reduced which would then allow you to move further up the steep hill.

##### Share on other sites
Of course. But that is quite correct behavior. The problem with getting uphill "diagonally" when hill is too steep is that car/whatever will slide, or possibly flip over. If car would not slide, it would be possible to pass steep hills diagonally (and to some extent it is possible in reality, in case car's motor is too weak to go directly uphill).

Indeed, sliding should be also considered in simulator, but sliding and flipping that's other story. (as slipping play role not only on hills but also on turns)

^^^^ was me.

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633761
• Total Posts
3013724
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!