Pitching against a terrain (a little long)

Started by
5 comments, last by silvermace 19 years, 4 months ago
So, I am trying to get a small vehicle to pitch against the terrain it is driving on so that when its going up or down hill it actually looks normal. My problem is essentially that I dont know a good way to tell if I am going straight... My original design simply had me getting the angle between the vector in the terrain that the vehicle is on and the vehicles position before I corrected it to have it go up-hill (for example if it were going uphill it sort of just drives straight and gets bumped up to keep it on the terrain). This gave me angles that were way too small. My second design had me taking the vehicles position and getting the angle between that vector and the same vector without the height. This worked beautifully going up or down hill (had to figure that out myself because with this scheme I never got a negative angle). It sucked when I was on straight terrain though. Basically I would find myself pretty much always rotated somewhat and in certain cases perpendicular to the terrain. My third scheme which I havent tried is to define some height level as ground level and anything above or below that is above or below ground, respectively. I would then get the angle between the vehicles actual position and the x and z coordinates with the ground height. This sounds like it could work assuming the only time i have flat terrain is at ground level but my terrain has canyons and pleataus so I am out of luck. SOmething that just occured to me...if I keep track of net change in height I could use that to assume if Ive gone up or down hill and just ignore pitching if that change isnt past a certain threshold...does that sound like it might work or is there an obvious problem that I am not seeing at the moment? ALternatively, instead of fixing one of my schemes, how is this thing normally done? Thanks.
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
Advertisement
I'm just brainstorming here, but.

Couldn't you just keep track of the height of the terrain under each axle of the vehicle and pitch the vehicle accordingly? That's really what it is, isn't it? If the terrain under the front axle is higher than the terrain under the rear axle, you are pitched up, and vice versa.

You could even set a particular threshhold for terrain that's too steep to climb this way.

Add a check for a point midway along the length of each side of the vehicle and you get roll as well as pitch, in case the terrain is uneven side to side.

Edit: clarification
That sounds like a pretty sweet idea ;D For some reason I never considered using more than one vertex to check the vehicles height...

When I get back from classes I will try that out immediately and let you know how it worked.

Thanks.
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
do a dotproduct between the vehicles up and the normal of the terrain, if theyre the same the result will be 1.0
Ok...

Using multiple vectors to get the height at the front, back, left and right is giving me really small angles and so it doesnt look realistic enough.

I am going to try using the up vector (always 0, 1, 0) and the terrain's normal vector at the vehicles position to get the angle. My question is this: Will using the vehicles right vector and the terrain's normal vector give me the right angle for roll?
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit."-Aristotle
Simple method:

new_right_vector = old_right_vector
new_up_vector = terrain_normal
new_forward_vector = CrossProduct(new_up_vector, new_right_vector)

Then you use these vectors to build your orientation matrix.

The simplest way to get the terrain_normal is to use the normal of the point under the center of the vehicle for example. You can also get fancy and average the normals of the polygons under each wheel of the vehicle.

james
find the angle between the horizontal axis (x and then z) and the vector perpendicular to the normal along the same axis, this will give you your rotation angle for that axis.

(incase you didnt know, dot product yeilds a scalar value that can be used to determin the angle between two normalised vectors: clicky)
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement