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.

DarkBASIC Professional Discussion / Ballistics... anyone?

Author
Message
MicroMan
22
Years of Service
User Offline
Joined: 19th Aug 2003
Location: Stockholm, Sweden
Posted: 30th Aug 2003 19:23
Beyond Pytahogas, my math is terrible. I'm definately a right-side-of-the-brain type of guy, which brings me to my question. I've got a gun turret, lobbing magical grenades -- but they have to fly in an arcing orbit. It also affects the arrows and crossbow bolts in my game -- but to a lesser extent of course.

Is there a formula to calculate this orbit?

-----
They SAID that given enough time a million monkeys with typewriters could recreate the collected works of William Shakespeare... Internet sure proved them wrong.
-----
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 30th Aug 2003 21:02
There could well be a formula, but the easiest way to do things is to model the movement using x,y,z speed vectors. Then just position the object each program loop at its current position, plus each of the x,y,z speeds. To get the curve, you then just add a gravity constant to the yspeed.

Ya variables
xspeed# = 0
yspeed# = 0
zspeed# = 0
Gravityconstant# = 0.01

To calculate what speed each variable should be, based on the angle of your turret, plus the overall speed you want the projectile to be launched at:
xspeed# = shotspeed# * cos(turret_y_angle)
yspeed# = shotspeed# * sin(turret_x_angle)
zspeed# = shotspeed# * cos(turret_y_angle) * cos(turret_x_angle)

(Thanks to Ed for helping me out with those equations a while back)

Then simple move the object based on its speed each loop, and add a gravity contant to the yspeed# each loop:
yspeed#=yspeed# - GravityConstant#
position object obj,object position x(obj)+xspeed#,object position y(obj)+yspeed#,object position z(obj)+zspeed#

Hope that helps.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
MicroMan
22
Years of Service
User Offline
Joined: 19th Aug 2003
Location: Stockholm, Sweden
Posted: 30th Aug 2003 21:28
Thanks a lot, I appreciate it!

-----
They SAID that given enough time a million monkeys with typewriters could recreate the collected works of William Shakespeare... Internet sure proved them wrong.
-----

Login to post a reply

Server time is: 2026-07-25 09:38:40
Your offset time is: 2026-07-25 09:38:40