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.

Code Snippets / physics gravity velocity x y

Author
Message
fire
20
Years of Service
User Offline
Joined: 30th Jul 2004
Location: israel
Posted: 16th Sep 2006 19:56
its kind of a game i guess
works 100%
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 17th Sep 2006 05:55 Edited at: 17th Sep 2006 05:58
It's a neat code snippet.
y#=y1+v0*sin(angle)*t#-g*(t#*t#) makes sense for calculating the y position based on the time and initial velocity, but when programming, you'd normally find it easier to do something like this:

Before the loop, set vx#, vy#, x#, and y# to their initial values, based on speed and angle:
vx#=v0#*cos(angle#)
vy#=v0#*sin(angle#)
x#=x1
y#=y1

During the loop, you'd update the variables, like this:

rem increase y position by y velocity each frame
y#=y#+vy#*t#

rem decrease y velocity by gravity each frame
vy#=vy#-g#*t#

rem increse x position by x velocity each frame
x#=x#+vx#*t#

Programming it this way makes it easier to add things like bouncing or whatever later on, and you don't need to write any extra equations to find the current velocity of the projectile.

Login to post a reply

Server time is: 2024-11-23 03:58:27
Your offset time is: 2024-11-23 03:58:27