Jump to content

Projectile From A to B


gamecreator
 Share

Recommended Posts

Hi there. I'm making a simpler version of Worms and I need code (C preferred) to get a projectile from X1, Y1 to X2, Y2 but I'm horrible with math. But it gets a bit more complicated than that. Depending on the situation, there may not be enough velocity to hit the target. So the problem is, given V, is there an angle that exists that will hit the target. If so, what is it (I think there may be two so I would need the steeper of the two).

 

I think this may be the formula I'm looking for (from the wiki):

 

8380d78ccac32ae4bcfdb6f3ef840613.png

 

Also, if I understand it right, that assumes X1, Y1 is at 0, 0 so I think that needs to be subtracted from (added to??) the target.

 

Any help would be appreciated.

Link to comment
Share on other sites

You don't need math with LE. Just use a pivot and do a PointEntity(pivot,target), then you can read the pivot's direction using EntityRotation().

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

If I understand this correctly he's not asking for the angle to the target as a straight line, which is what your suggestion would give but rather the vertical angle the projectile would need to be fired at given an x,y target position and a velocity to ensure the projectile hits it. Presumably this is a parabola flight path.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I would use physics for that. That's what made Angry Birds famous too :P There's incredibly little physics based games on the market, and they will have huge success if made well.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

No I believe he will be using physics but I think he's currently programming the AI so it knows what angle and velocity to shoot the projectile at to hit the target.

 

Gamecreator - To answer your question regarding the (x,y) I believe that they are relative variables. That is to say that the position of A is relative to that of B. So:

x = targetA.x - targetB.x // That'll get the meters between the launch site and the target

y = targetA.y - targetB.y // That'll get hte height of the launch site relative to the target

 

You'll have to mess around with the order of subtraction there I'm guessing, so you don't get any negative values.

 

Do you know how you're going to solve whether it will hit geometry or not?

Programmer, Modeller

Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64

Visual Studio 2008 | Photoshop CS3 | Maya 2009

Website: http://srichnet.info

Link to comment
Share on other sites

Right well that equation should get you that, but it won't tell you whether it'll reach its target. You'll need to test each angle and velocity with a collision check to find one that won't hit geometry.

Programmer, Modeller

Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64

Visual Studio 2008 | Photoshop CS3 | Maya 2009

Website: http://srichnet.info

Link to comment
Share on other sites

The good thing is that there are second chances. The computer, like the player, is allowed to miss. But if the projectile doesn't hit, it would be because the shot can't be made (because there won't be any wind or overhead obstructions). In that case, the computer will need to switch to a different target. Or a bigger weapon. :P

Link to comment
Share on other sites

Angry Birds gets mentioned a lot and while yes it's a simple physics game, its success (and they made 50 games prior to that) is the huge effort and experience applied to presentation then giving it away to create it as a brand.

 

 

For ballistics see this for a quick simple example of what you want.

 

http://warpycode.wordpress.com/2009/10/10/aiming-a-projectile-uphill/

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Haven't had a look at those sites that NA posted but this is what I came up off the top of my head.

 

Its basically calculus and Newton's law F=MA or rather F=MU for instantaneous speed (U initial velocity)

 

Apologies that this is hand written. I have simplified the calculus part by using pre-determined physics acceleration equations. Hope you find it useful.

 

using these equations you should be able to determine the force required for a given mass and the angle to apply the force at. good luck

 

some definitions:

s- distance (m)

v- final velocity (m/s)

u- initial velocity (m/s)

a- acceleration (m/s2)

t - time (s)

 

post-3220-0-54737700-1324737272_thumb.jpg

post-3220-0-69035800-1324737300_thumb.jpg

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...