Original Post
Howdy,
I'm trying to simulate a ball interacting with its environment, and have a couple of questions.
Q1: How do I get the ball to 'roll' along an arbitrary terrain?
Q2: How do I get the ball to accurately bounce off an arbitrary terrain?
Q3: What is the correct way to calculate the correct collision angle off a surface.
To show that I am not just posting in ignorance, here's what I'm currently doing.
The ball has three vector properties. X,Y,Z for its position. dX,dY,dZ for its direction and aX,aY,aZ for its acceleration.
In terms of Q1, I am constantly adding a gravity acceleration to the aY vector, which pulls the ball down. I can check for collision with the terrain no problem using radius coldet, and I can calculate the x/z gradient of the terrain at the collision point. Basically I add the gradient vector (?) to the acceleration vector and hope for the best. The problem is that when the terrain gets intensely deformed, this method breaks down because several parts of the ball are potentially touching the terrain.
In terms of Q2: and Q3: (which are probably the same question anyhow), I have no problem with calculating WHEN a collision occurs with either the terrain or a flat surface (like a wall) on the terrain, but I can't seem to get the reflexion angle correct. To put this a bit more clearly:
If the ball is travelling in 2d space, and is moving downwards at 45-degrees to the left, and hits a vertical wall, then the ball should reflect to move down and to the right at 45-degrees. This is fine assuming that the wall is infinitely tall. However, if the ball collides with the top corner of the wall (which can happen with finite walls), then the ball would bounce up and to the right at 45-degrees. In 2d simulations I can easilly check to see which part of the ball hit the wall (top, left, bottom, right, or a combination of two sides) to get the correct reflection. In 3d this gets a lot more complex and time consuming.
Now, I could just check for a collision at the point on the balls surface that corresponds to center+radius along the direction of dx,dy,dz, which would give me a collision at the point of forward motion. Then I could 'bend' the dxdydz according to the gradient of the surface hit, but this doesn't cater for cases where the edge of the ball hits an object, which would mean that I could have the ball travelling through objects.
Anyway, I'm a bit stuck at the moment. What I have is semi-working, but it doesn't work perfectly in all situations.
Any help would be great.
[edited by - Nottaxes on January 15, 2003 1:43:18 PM]