Vehicle collision and rotation

Started by
2 comments, last by Monkan 12 years, 8 months ago
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

"To know the road ahead, ask those coming back."

Advertisement
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 normal 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.
Success requires no explanation. Failure allows none.
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.

"To know the road ahead, ask those coming back."

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.

"To know the road ahead, ask those coming back."

This topic is closed to new replies.

Advertisement