Jump to content
  • Advertisement


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


Worm - LIke Game

This topic is 6081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetz, I would like to make a game kinda like Worms but don''t have a clue how to implement the effects of Gravity and wind on the cannonballs or whatever object Any help would come in handy bye Greetings from the one who knows so little

Share this post

Link to post
Share on other sites
All i remember is thers a trig info on the balistics of a cannon ball.

i dont remember where to find it but look in some trig books for balistics thats where i found some info when i remade scorched earth (tanks instead of worms )

about the wind if i remember right its like gravity but left or right.

Sorry if im no help!!!!!

The best RPG has yet to come into being (only ''''cause I cant do it all

Share this post

Link to post
Share on other sites
Just ot let you know: inertia would be another good thing to implement so they don'' just go top speed when you first push the arrow key and don''t just stop when you stop...

Share this post

Link to post
Share on other sites
Gravity is a constant downward acceleration. The easiest way to deal with this is to use simple Euler integration. Here's how:

First, create a vector representing the initial velocity of the cannonball.

I'm assuming you don't know what a vector is. A vector is a direction and a magnitude, something like "200 mph southeast." Mathematically, they are usually expressed in component form . Think of it this way: If you shoot a bullet and look at it in a 2d overhead view, what is its x value at one second? At two seconds? At three? What are its y values at each? You will find that the x value increases by a constant amount each frame, as does the y value. If it moves by 2 units in the x axis each second and by 5 in the y axis, then a vector could be written (2, 5) . This concept can be extended to 3d, with x, y, and z axes. I will refer you to the articles here on gamedev.

Now, you ask, "how do I find this cannonball velocity vector?" Well, let's look at this in 2d - now from the side.

/ The cannonball is fired from point p
/ upwards at a speed of 60 meters per second.
/_ The angle at which it is fired is Theta.
/ \ <-- Theta

Using simple trig, you can tell that the cannonball will move upward 60sin(theta) meters each second (without gravity) and 60cos(theta) meters forward each second.

Now, we need to factor in gravity. gravity is a constant downward acceleration. Now think of what acceleration is: a change in velocity . Velocity is a vector quantity; it represents both direction and speed (magnitude). So is acceleration. So, to accelerate something, you add an acceleration vector to the velocity vector.

Gravity for our purposes (since we're near the surface of the earth) is a constant acceleration vector. It is 9.81 m/sec2(0, -9.81) .

Hopefully you now have a basic idea of how to proceed. I'll help you out though by giving you some basic pseudocode:


ball.velocity.x = speed * cos(theta);
ball.velocity.y = speed * sin(theta);

for(each frame)
//Add velocity to position

ball.position.x += ball.velocity.x; // x component

ball.position.y += ball.velocity.y; // y component

//The x component of gravity

ball.velocity.x += 0; //This can obviously be removed

ball.velocity.y -= 9.81; //This is the important part


After a while, continuously subtracting 9.81 will make the y component of the velocity zero (at which point it will hover motionless for the smallest instant at the top of its arc), and the subsequent subtractions will make it negative, and it will begin to fall back to earth, getting faster and faster.

Note that my number, 9.81, is in meters per second on earth. This number may not fit your game scale, and you may also want your gave to have lower or higher gravity than earth. So you can change it.

Also remember, of course, that all units are units of length per second . This means that if you want to keep a constant behavior at all framerates, you'll need to multiply all constants by the amount of time it took to render the frame (eg, divide by FPS).

This is the end of super-basic physics 101. You shoudl be able to get started now. Good luck in your game!

[edited by - TerranFury on April 19, 2002 5:50:44 PM]

Share this post

Link to post
Share on other sites
That's got to be the best explanation of a vector and simple projectile motion I've seen. Kudos to you TerranFury!

[edited by - UBC_Wiskatos on April 19, 2002 8:46:51 PM]

Share this post

Link to post
Share on other sites
Wow, I have to agree, that explanation was great - much better than any book I''ve seen! TerranFury, do you know of any books with that kind of detail? Andre LaMothe''s books that contain a physics chapter always suck That post was really good, I''m saving it

Share this post

Link to post
Share on other sites
Thanx for the detailed explanation, I''ll try it out (as soon as I find the time for it)

Very much thank you !!

Greetings from the one who knows so little

Share this post

Link to post
Share on other sites
The explanation above was not correct. Close, tho. The physical modelling of a projectile is counted by the following formula
x = cos(a) * v * t
y = sin(a) * v * t - ((1/2) * g * t * t)
x is the horizontal distance travelled (in meters)
y is the vertical " " "
a is the angle where the projectile was shot
v is the initial velocity in meters/second
t is the time the projectile has travelled so far (in seconds)
g is the gravity in meters/second^2

the gravity of earth is 9.81 meters per second squared. the same number for moon is 1.62 m/s^2, for jupiter it is 25.9 m/s^2 and for saturn it''s 11.3 m/s^2. I implemented different gravities in I once coded a simple artillery duel (with a real retro feel''n''all) where the I had different gravities of planets. gravities lower than moon and higher than saturn made the game impossible to play.

modelling the wind ACCURATELY is a tougher one. the effect of wind changes as by the shape of the projectile. the most simple way is to calculate x like this
x = sin(a) * v * t + wind * (delta)t
x,a,v and t are the same as above.
wind is the speed of the wind (in meters/second)
(delta)t is the time passed since the last calculation.

i''d suggest you have a 25 m/s maximum for the wind and 50-100 m/s maximum for the initial velocity to make a nice feel to the game. This gives an average shot of 100-500 meters, so make your playing area at least 1 kilometer long.

you can try to find an university-level physics book with more detailed explanation of the wind and air viscosity and stuff like that. I would stick to these as they are accurate enough for a game.

Hope this helps, Richardo

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!