Sign in to follow this  

Pitching against a terrain (a little long)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this