Sign in to follow this  
Monkan

Vehicle collision and rotation

Recommended Posts

Hi,

So I'm putting a vehicle into my game, a Jeep to be precise.

My game is 3D and I have the terrain made from a heightmap. Using this I can calculate point collisions with the terrain which works fine.
I figured I would make my jeep out of 4 wheel objects which would be used to calculate the collision with the terrain to ensure they are on top of it and then draw the body of the jeep so it is in-line with these wheels. Is this a valid way of doing this? So I presume I will need a wheel model and a jeep body model.

Then I have the problem of rotating the body model so it is on-top of the wheels. So far I have the wheels lining up fine with the terrain but how would I calculate the correct rotation matrix to apply to the body so it lines up with the wheels correctly? I have the positions of the wheels so from that I have to somehow work out the rotation. Can someone please advise me or point me in the direction of a tutorial.

Thanks
x

Share this post


Link to post
Share on other sites
I can't point to a tutorial off hand and also can't recall the math, but what you're looking to do is rotate the Jeep's model to orient to the [i]normal[/i] of the wheels. A surface normal is a vector that projects out of the face of a polygon. If you created a rectangle with each wheel as a vertex, then the surface normal would be the direction you should orient the body to make it fit properly. You shouldn't have too much difficulty finding the math needed to calculate this from the locations of the wheels.

One word of caution though: if you're implementing any sort of suspension then the wheels probably won't be in a single plane any more. You would then need to find some way to calculate the normal differently. You could maybe create four triangles and average their normals (one triangle that includes every wheel but one, for each wheel), but that might not look perfect. I imagine modern games probably have more complicated ways of doing this.

Share this post


Link to post
Share on other sites
Thanks for your reply,

That makes sense, my terrain already has normals calculated so I could use the ones from each triangle on the terrain that each wheel is on and then average them.
If I remember correctly averaging normals means adding them together and then normalising the resulting vector.

I'll give this a go for now and then have another think when I come to add suspension and the like.

Cheers
x.

Share this post


Link to post
Share on other sites
Ok so I've got my normal which is the direction I want the body of the jeep to be sloping.

How do I actually rotate it to align it with the normal. I presume I need to rotate around the y axis so that the body is facing in the direction the jeep is facing and then rotate around the x and z axis so that the jeep is aligned with the normal?

Help please.....
Cheers.

Share this post


Link to post
Share on other sites

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