Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Projectile Motion (Parabola)

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 PsionicTransvection   Members   


Posted 17 August 2012 - 06:58 AM

So here is the thing I`m working on a small game which it looks like this

Posted Image

there are 2 tanks shooting at each other in turns and you are supposed to change the angle (moving arrow up or arrow down) and the power with which the projectile is flying (holding down the space the longer you hold the more power the projectile gets).

So far managed to make a small figure moving around the screen and shooting but until this point I made it shoot only in a straight line
searched a lot of links and videos about this problem I found the formulas needed for calculating the curve but still have problems applying it in my code :/ I`m open to any suggestions or criticisms I`m sure I`m doing something wrong all advices and code examples will be gladly appreciated looking forward for your posts I really need help with the parabola problem .

Here is the shoot method which makes the projectile move it`s a rectangle :

(sorry for not putting the code in tags for some reason when I do it does not print the whole code)

public void shoot()
if (shot)
bullet.x -= 5;

if (bullet.x <= 0)
readyToFire = true;
boom = true;
//power = 0;


I also attached a rar with the whole code so far it`s only 2 classes it`s not much

Attached Thumbnails

  • tanks.PNG

Attached Files

Edited by PsionicTransvection, 17 August 2012 - 07:52 AM.

#2 Faelenor   Members   


Posted 17 August 2012 - 07:18 AM

You should have a look at some 2D physics references. I found this cute tutorial (http://www.rodedev.com/tutorials/gamephysics), it seems to explain what you're trying to do. You should be able to find a lot of material on 2D game physics on the web.

#3 Andy474   Members   


Posted 17 August 2012 - 07:19 AM

your best bet is to use vectors.
Your bullet come out of the gun at a certain velocity, so for instance:
Vector2 bulletVelocity = Vector2.Transform(new Vector2(-bulletPower),0), Matrix.CreateRotationZ(turretRotation));
//rotates the bullet coming out of the turret.

this will make the bullet zip across the screen in a linear fashion, to make that parabolic effect, addGravity:

void updateBullet() {
	 Gravity = new Vector2(0, -9.837f);
	 bulletVelocity += Gravity;

http://www.riemers.n...rp/series2d.php this article talks about and the type of game your making, thats c# using XNA, same principal can be applied to java though.

Edited by Andy474, 17 August 2012 - 07:22 AM.

#4 nox_pp   Members   


Posted 17 August 2012 - 07:31 AM

You don't need to calculate the parabola, you can just use Newtonian mechanics, and it will naturally follow a parabolic path. Andy's answer is pretty much correct, but you will have to integrate your calculations with respect to your timestep.


If you want to make something very simple, without actual physics, you can easily calculate the parabola, and just solve the equation f(x) for some increasing/decreasing x on each timestep, and then move your projectile to the point (x,y) given by the solution.

Edited by nox_pp, 17 August 2012 - 07:33 AM.

Between Scylla and Charybdis: First Look <-- The game I'm working on


Object-Oriented Programming Sucks <-- The kind of thing I say

#5 germangb   Members   


Posted 17 August 2012 - 06:09 PM

a parabolic throw consists of 2 movements: vertical (accelerated because of gravity) and horizontal (constant). That way, if you're working with pixels, you could simulate the action of gravity by adding some value to the vertical velocity in every frame, wich should point upwards at the begining.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.