# 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.

## 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 on other sites
complicated.

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

##### 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 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634133
• Total Posts
3015747
×