Think of the ball as a big sphere particle. You have position and movement vectors (3D-vector is x,y,z coordinates). Each game tick ball's position vector is increased by its movement vector, and movement vector's Y-coordinate is decreased by gravity. When ball hits ground level, position vector is moved on top of ground, movement vector is scaled down by.. say multiplying Y with 0.3 (so next jump is smaller than last, in football much smaller) and Y is turned negative (this is the bounce effect).
But when we take grass into account we know that certain point ball won't bounce up anymore but instead starts rolling. You can by testing see by maybe "if movement vector's Y is < 0.2 then movement vector's Y = 0.
Code:
if KickKeyPressed then begin
moveY:=KickStrength*0.9;
// feel free to change constant fitting, this effects angle that
// ball flies upwards
moveX:=KickStrength*cos(RadAngle);
moveZ:=KickStrength*sin(RadAngle);
end;
moveY:=moveY-gravity;
posX:=posX+moveX;
posY:=posY+moveY;
posZ:=posZ+moveZ;
if posY-BallRadius<groundlevel then begin
// hits ground
posY:=groundlevel+BallRadius;
if moveY<-0.1 then // if speed 0.1 is lowest bounce after rolling starts
moveY:=-moveY*0.3 // bounce up
else
moveY:=0; // start rolling
moveX:=moveX*0.993; // Again feel free to experiment with slow-down constants
moveZ:=moveZ*0.993;
end;
Bookmarks