Simulating ball movement in 3D space
Heya all !
I'' trying to simulate the movement of a ball in 3D space, but I came across serveral difficulties.
I found out how I calculate the velocity vector that slows the ball down ( or even changes it''s direction ), when the ball is moving on a slope surface:
it''s the straight that you get when you cut the surface with
a surface that passes through the normal of the surface and the X3 vector.
you can calculate it''s length by
F = sin a * G ( where a is the angle of the surface to the ground ).
What I now need to know is the following:
My routine checks the angle between the current movement direction ( vel vector ) and the planeNORMAL of the plane ( it just hit, or is currently rolling on ) if it''s below 90° the ball is in free fall mode, so a simple trajectory is evaluated ( and traced for possible hits with ground or walls, etc ). if it''s between 90° and 135° the X3 coordinate of the velocity vector is adjusted so that the ball rolls on the surface ( velocity vector is parallel to the surface then ) and it''s length is preserved. If it''s any other angle the ball bounces off by reflecting the velocity ( I did this with -2*dotproduct of dir and normal, but gives strange effects sometimes - see below )
Now there is a problem the last case means if the angle of the wall and the
surface the ball is rolling on is > 90°
the ball bounces off, which is totally correct, if we are talking about a horizontal floor and a vertical wall. But if we have two SLOPES which have an angle 90° degree a real ball would roll over the gap instread of being bounced off, because of it''s rotation. Concerning the same two surfaces the ball behaves very strangely: while bouncing between those two surfaces tha ball gets slower and the bounces get samller towards the gap - as it should be - but instead of stopping it suddenly get''s pushed away like hell by one of the surfaces.
One problem I see is that I always calculate the theoretical endposition if no collision would occur and
then call a trace routine giving it the start and the endpos and the bounds of the ball. The trace returns the fraction of the way from start to end he could travell LINEARY without hitting a plane. If all went fine the fraction is 1 if not it is something between 0 and 1 also returning the position where the clollision occured and the normal of the hit surface. So the problem is that even if you evaluate a trajectory the trace routine assumes
the movement in a straight line from start to end. But my routine is called ~ 10 times a second, so the approximation the routine makes by tracing a straight line is is not too grave.
After reading though all this I would consider it very nice if you could give me any advices how to fix these probs ( Or even tell me a better way to do all of it ;-) - maybe one where I don''t have to distinguish between the different angles ).
Thanx in advance.
C ya
Lightsaber
P.S.
For all of you interested - what I code is a Q3 mod so the way the traces are done are fix and can''t be altered by me.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement