Archived

This topic is now archived and is closed to further replies.

dbapollo

How to do the trajectory in a projectile-motion shooting game? (ala-"Worms")

Recommended Posts

Im conceptualizing this game that has mechanics which are similar to: Scorched Earth, the Worms series and Gunbound (if you havent heard of the games, feel free to google them ) Anyway, I was wondering if anyone can suggest a good way of implementing the use of projectile motion in java considering these factors: - the player would have to adjust the angle of the shooter and determine the power at which the projectile would be shot - the projectile will then follow a path determined by the angle and strength it was shot - basic physic laws apply - (i dont know if i will implement a "wind drag" feature yet to the game) - J2ME Specific: J2ME does not use the data types: float and double Ive been considering lots of physics related stuff such as: the path of the projectile (how to compute for it and how to draw it), and the speed of the projectile <<< these are my biggest problems for now. I have been considering how to do this for a LONG time now. any type of help will be GREATLY appreciated, thanks!!! [edited by - dbapollo on March 19, 2004 12:37:04 PM]

Share this post


Link to post
Share on other sites
(You double-posted, please delete the other one).

Here are some answers to your questions:

1° The physics laws you are talking about (the ones that apply to moving objects affected only by gravity and drag) are Newton''s laws, and are expressed in terms of variations : x and y both change over time, their rates of change also change over time, and the rates of change of their rates of change are the forces that are applied to it... See it like this (for one coordinate) :

x is the position
dx is the change rate (aka the speed)
d(dx) is the change rate of the change rate (aka acceleration)

then d(dx)*M = Forces_x (where M is the mass of the object).
same for y...

Example of a moving object with drag & gravity (assuming y is pointing up) :

M*d(dx)= -k*dx
M*d(dx)= -k*dy - M*g

Now, how to do this in terms of computer simulation? You want to get x from dx, and dx from d(dx). This is easiest done using euler integration, which basically coes like this :

x <- x + dx*t
dx <- dx + d(dx)*t

Where t is the time that elapsed since the last time you computed x and dx. (t does not have to be "real" time : you could for instance have t be smaller when doing slow motion replays).

To launch a projectile at an angle and speed, just set the position and speed using trigonometry, and then let the physics system do it off its own.

About the floating-point operations not being available : use fixed-point math (search for it off google, I''m sure there are some things available).

The part about drawing the projectile, well... I''m no Java programmer so I won''t be able to help you there.

Victor Nicollet, INT13 game programmer

Share this post


Link to post
Share on other sites