Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Balls to Physics!!!!!

Author
Message
Mincher
20
Years of Service
User Offline
Joined: 23rd Sep 2003
Location:
Posted: 23rd Sep 2003 15:56
Hey everyone, im having a little trouble getting ball physics to work. My player object picks up the ball when contact is made and he throws it when the relevant key is pressed. The problem im having tho is getting the ball to slow as it reaches a certain distance and also to curve parabolically when thrown (like a cannonball). Any help or ideas would be much appreciated.

mix_master_mincher
Ken
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 23rd Sep 2003 17:56
You need a few variables:

Your object's X,Y and Z velocities
a varible for gravity
and one for air resistance

Add your X,Y and Z velocities to the relevant X,Y and Z positions
Decrease your Y velocity by the gravity value

Easy part done

The harder part is the air friction, which you can get away with not having unless you want ultra-realism.

Air friction is a function of velocty squared and operates against the direction of travel.

Calculate the speed:

speed = sqr(xv ^ 2 + yv ^ 2 + zv ^ 2)

Normalise the velocities:

xv = xv / speed
yv = yv / speed
zv = zv / speed

Apply friction:

speed = speed - friction * speed ^ 2

Calculate the new velocity vector:

xv = xv * speed
yv = yv * speed
zv = zv * speed
Ken
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 23rd Sep 2003 17:58 Edited at: 23rd Sep 2003 18:00
Oh, just forgot. You need to check your speed doesn't go below zero and you'll need to experiment with different values of gravity and friction to get what you think looks best, but try small values of around 0.01 first. You also need the initial X,Y and Z velocity vector to be in the direction you want the ball to be thrown in.

Login to post a reply

Server time is: 2024-09-21 01:15:49
Your offset time is: 2024-09-21 01:15:49