Page 1 of 1

Trying to simulate the flight of a golf ball

PostPosted: Tue Dec 14, 2010 12:54 pm
by TommyComputer
Hello,
I'm new to Game Editor and trying to make my first game, based on golf. I can set a golf club with speed and angle to get a ball hit up into the air by the player, but the bounce using collision doesn't look natural and it doesn't stop. Any tips would be appreciated.

Re: Trying to simulate the flight of a golf ball

PostPosted: Tue Dec 14, 2010 10:27 pm
by skydereign
To make it look really accurate, you will have to calculate the velocity of the ball, given angle and speed. Then on collision set the velocities of the ball. Generally you can use angle and directional_velocity, but depending on your calculations, or lack thereof, there will be varying levels of accuracy.

Re: Trying to simulate the flight of a golf ball

PostPosted: Tue Dec 14, 2010 10:28 pm
by DST
Ball>draw Actor>
Code: Select all
directional_velocity *=.98;   //make ball slow down
if(directional_velocity<.01){  //make ball stop if nearly stopped (prevents shaking)
directional_velocity=0;
}


You can also then create a float (real) array, and set the slowdown for terrain types;
for instance
Code: Select all
tslowdown[0]=.998;  //speed to slow down while in air
tslowdown[1]=.99;    //speed to slow down while on grass
tslowdown[2]=.90;    //speed to slow down while on sand


then have the ball start with a terrain of 0; and change that to 1 on collision with ground, or 2 on collision with sand trap.

then
Code: Select all
directional_velocity*=tslowdown[terrain];


You could just nix the slowdown in the air, that may be best if it doesn't slow down till it hits something.

Then on your collision, try adjusting the power of the ball. There are 4 variables in physical response;
The 3rd one is 'final velocity multiplier' for event actor. You can adjust this till you get a response you like.

Re: Trying to simulate the flight of a golf ball

PostPosted: Wed Dec 15, 2010 5:11 pm
by TommyComputer
Thanks - I will try that straight away