Advertisement Jump to content
Sign in to follow this  

Box moving over a plane ?

This topic is 4992 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

Hi! I'm a beginner at OpenGL and collision detection. My problem is: I have a box that is supposed to move over a curvy ground, like hills and holes. And I want the box to follow the grounds curves and hills. Like a car moving in bumpy terrain. How would I make a collision detection for this so it works like I want to? Thanks for any help. :)

Share this post

Link to post
Share on other sites

Simplest solution, pick up the ground position and direction under the car, and orientate the car and position it accordingly.

Share this post

Link to post
Share on other sites
Yeah, I've figured that out already. I was thinkin maybe to get the face and calculate the normal and so on. some help code maybe.

Share this post

Link to post
Share on other sites
depends what kind of surface you are using. If it's a heightmap, it's quite easy. If not, it will be more difficult.

sometimes car racing games use raycasts, and cast a short ray or segment from the wheel bearing to the ground. The intersection gives you the contact patch for the tire. The intersection will have the normal and point on the ground.

you can approximate this for the whole car by intersecting a segmentfrom underneath the car the same way. Then you'd get a normal and point of collision from where to place the car.

to calculate ray-ground intersections,

3D object intersection

and to re-orientate the car to the ground normal, you need the car orientation matrix.

Matrix O; // orientation of the car / character / object
Vector N; // normal of ground that you found

// the major axes of the car, from a row-major orientation matrix
Vector X = O.GetRow(0);
Vector Y = O.GetRow(1);
Vector Z = O.GetRow(2);

// Cross product right-handed rule :
// ---------------------------------
// X x Y = Z
// Z x X = Y
// Y x Z = X

// re-orientate the major axis so now Y = N
Y = N;
X = Y.Cross(Z); X.Normalise();
Z = X.Cross(Y); Z.Normalise();

// Update car orientation
O.SetRow(0, X);
O.SetRow(1, Y);
O.SetRow(2, Z);

for column-major matrices, obviously, use columns.

the last Z.Normalise() should be unnecessary.

That will ping the car directly to the orientation on the ground.

to make it smoother, you'll have to use quaternions, build a quaternion from the ground normal and the car direction, and SLERP the car quaternion orientation to that one.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!