This code snippet could be useful for creating a game like the world famous qbasic's: Gorillas. Adjusting the angle and speed of the cannonball would be required.
Code archives/Algorithms/Basic Cannonballs Physics 3D
This code has been declared by its author to be Public Domain code.
Download source code
| . |
. |
Comments
Nice Work! Short and OK.
Look also to my Prg, it may help for more.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1164
feel inspired.
Look also to my Prg, it may help for more.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1164
feel inspired.
"theduck" - here is a more general equation for what you are doing.
new y = -0.5*gravity*time*time + initial y velocity * time + initial y position
new x position = initial x position + time* intial velocity in x direction
new z position = initial z position + time* initial velocity in z direction
If you use a scale of 1 blitz unit = 1 metre then gravity should be (for Earth) 9.8.
Time is usually measured in seconds elapsed since cannon ball fired.
initial x, y ,z positions are the position of the ball prior to being fired.
This assumes a constant acceleration due to gravity as well as no air resistance.
initial x,y,z velocities are the velocities of the cannon ball in those directions as it is fired.
new y = -0.5*gravity*time*time + initial y velocity * time + initial y position
new x position = initial x position + time* intial velocity in x direction
new z position = initial z position + time* initial velocity in z direction
If you use a scale of 1 blitz unit = 1 metre then gravity should be (for Earth) 9.8.
Time is usually measured in seconds elapsed since cannon ball fired.
initial x, y ,z positions are the position of the ball prior to being fired.
This assumes a constant acceleration due to gravity as well as no air resistance.
initial x,y,z velocities are the velocities of the cannon ball in those directions as it is fired.