Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (582)
games submitted by our members
Games in WIP (503)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Arrow Bow Physics - Help!  (Read 3511 times)
0 Members and 1 Guest are viewing this topic.
Offline Andre Lopes
« Posted 2013-04-16 15:41:13 »

Hi Guys!
Well, after the almost-Success with my PacMan Tongue , i decided that now, for my college project, i will make a archer 2D game. Something like Sonic.

Well, since i have until september of 2014, i think i can learn it Tongue

Anyway, im researching about how the arrow travels in 2D... Im unsure if i should use a X^2 Equation or calculate the Epg + Epe .....
Im no Physics pro, thought i study a lot, and im kinda dissapointed with myself for not knowing that... But i thought i could post here and clear things up Tongue

Would you guys give me some tips Tongue Huh

tyy

Btw, i know calculus I, if that helps.

Online Phased
« Reply #1 - Posted 2013-04-16 15:51:03 »

Search of Projectile Motion will give you all the formulas.

http://www.youtube.com/watch?v=5ehanc7sQdY

Seems alright so far, gives the equations, what some of the variables are and does examples.

If you asked like 6 months ago, I would of been able to give you the formulas soo much easier with a explanation, I learnt projectile motion in physics last year.

EDIT: Projectiles travel in a parabola.
Offline Andre Lopes
« Reply #2 - Posted 2013-04-16 16:19:50 »

Search of Projectile Motion will give you all the formulas.

http://www.youtube.com/watch?v=5ehanc7sQdY

Seems alright so far, gives the equations, what some of the variables are and does examples.

If you asked like 6 months ago, I would of been able to give you the formulas soo much easier with a explanation, I learnt projectile motion in physics last year.

EDIT: Projectiles travel in a parabola.


Just Downloaded, Fun App. But it doesnt give me the Formulas Tongue
I will research with that in mind
TY!!!!!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2013-04-17 04:28:27 »

Parabolic move:
1  
2  
3  
4  
maxHeight = ((startVelocity ^ 2) * (Math.sin(theta)) ^ 2) / 2 * gravity
//measure x and y based on time (delta)
x = startVelocity * Math.cos(theta) * time
y = startVelocity * Math.sin(theta) * time - (gravity * time ^ 2) / 2

Offline Andre Lopes
« Reply #4 - Posted 2013-04-17 17:52:16 »

Ok, The time should be pre-calculated ? I mean, the time depends on the velocity, right?
And the YV ( max height) should be used so the arrow can travel to the middle going up and then starts going down?

Offline ReBirth
« Reply #5 - Posted 2013-04-18 04:15:12 »

You should already know your gravity (in pixel/s) and theta. If the point of where the arrow being shot is fixed, then you will have maxHeight in mind thus you get the startVelocity.

Time is amount of second passed since the arrow start moving. You need to calc the x,y for render. If you can't find right value for startVelocity, try by trial.

Offline Wolfe

Junior Newbie





« Reply #6 - Posted 2013-05-02 22:17:03 »

This I programmed this in processing (it is like something embedded into java with libraries) http://www.openprocessing.org/sketch/19867   but it should be understandable.
There is button for source code.
Online HeroesGraveDev

JGO Kernel


Medals: 214
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #7 - Posted 2013-05-02 23:02:51 »

Why do you need a formula with angles to make a parabola?

Use angles once when the projectile is fired to set the intial velocity, then increase the downward velocity by gravity each update.

Offline Agro
« Reply #8 - Posted 2013-05-03 02:32:22 »

If its 2D, its easy. You should have a direction vector(which is just your velocity normalized), so get the angle of that, and then subtract from your Y velocity to make a parabolic motion.

Offline pjt33
« Reply #9 - Posted 2013-05-03 11:43:36 »

Projectiles travel in a parabola.
In a vacuum. Arrows follow flatter paths.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online HeroesGraveDev

JGO Kernel


Medals: 214
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #10 - Posted 2013-05-03 12:02:14 »


Not neccessarily a vacuum. Any area not effected by gravity will do. It just happens that matter tends to exist around objects that have strong gravity.

Online Phased
« Reply #11 - Posted 2013-05-03 12:08:21 »


Not neccessarily a vacuum. Any area not effected by gravity will do. It just happens that matter tends to exist around objects that have strong gravity.

Now your getting further away.

Projectiles move in a perfect parabola due to the gravity, if gravity did not exist, the projectile would travel in a straight line in the angle you shoot.

Gravity will push down on the projectile, causing it to move in a parabola.

and to pjt33, not sure what a flatter path is, quick google search didn't return me anything useful, due to air resistance, it will not be perfect as the horizontal component will slow down, causing the flight path to not follow a parabola that is worked out without the the effect of air resistance.
Online HeroesGraveDev

JGO Kernel


Medals: 214
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #12 - Posted 2013-05-03 12:12:00 »


Projectiles travel in a parabola.

Except lasers.

Offline pjt33
« Reply #13 - Posted 2013-05-03 14:38:56 »

In a vacuum. Arrows follow flatter paths.
not sure what a flatter path is, quick google search didn't return me anything useful, due to air resistance, it will not be perfect as the horizontal component will slow down, causing the flight path to not follow a parabola that is worked out without the the effect of air resistance.
In the simplest model, air resistance directly opposes direction of motion, so it affects the vertical component too. I once did some work on finding suitable air resistance parameters to fit known shell ranges and predict ranges for other shells for a historical warfare game, but I don't remember the values which I came up with.

For arrows the gyroscopic effect is likely to be quite significant in preventing the arrow from curving away from the straight line it would naturally follow. (Of course, it's never that simple: there's also precession to take into account...)

"The Mathematics of Projectiles in Sport" by Neville de Mestre might be worth getting hold of for people who are interested in realistic simulations.

PS HeroesGraveDev, stop digging.
Offline quew8

JGO Coder


Medals: 23



« Reply #14 - Posted 2013-05-03 19:58:37 »

I think for an arrow, the gyroscopic effect can be simulated fairly accurately by using an augmented version of gravity - say 7 instead of 9.81 (not that I tend to use 9.81 anyway (not using metres for the scene and seconds for the delta and all) but you get the point).

 

Lasers are light which is still effected by gravity (why black holes are black), so they do still follow a parabolic path, its just they leave the noticeable effects of Earth's gravity before it can have any noticeable effect on it. See monkey and hunter.
Offline Agro
« Reply #15 - Posted 2013-05-05 04:42:25 »

Yeah, light goes too fast to see effects in Earth. But farther out in space, like near a black hole, light and time can both be affected noticably.

Offline quew8

JGO Coder


Medals: 23



« Reply #16 - Posted 2013-05-05 11:46:44 »

True, but I'm pretty sure that when time itself is being warped by a black hole, it is hard to predict exactly what parabolic path an arrow would take. Probably best not to set an sonicesque archer game anywhere near a black hole. Unless it was directly between two black holes where they cancelled each other out, and the catch is that they are pulling themselves towards each other and crushing you so if you don't complete the game before the black holes arrived then you get compressed down into nothing.

(Has revelation for game about quantum effects, realizes most people aren't nerdy enough to play it)
Offline Agro
« Reply #17 - Posted 2013-05-05 18:49:48 »

Well, under a black hole, we can't really tell what will happen at all... After all, after a certain point, you can't see light anymore.

Offline DrZoidberg

Senior Member


Medals: 10



« Reply #18 - Posted 2013-05-05 19:29:10 »

How did you get from arrows to black holes?
Anyway, basically you can do it like this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
class Arrow {
    double x, y,
           speedX, speedy;
   
    double gravity = 10;
   
    void setSpeedAndAngle(double speed, double theta) {
        speedX = Math.cos(theta) * speed;
        speedY = Math.sin(theta) * speed;
    }
   
    //dt = delta time
   void update(double dt) {
        y += speedY * dt + 0.5 * gravity * dt * dt;
        speedY += gravity * dt;
        x += speedX * dt;
    }
}
Offline lithos

Junior Member


Medals: 1
Projects: 1



« Reply #19 - Posted 2013-05-06 04:09:34 »

The Squared/cubed/further and extra X functions for velocity/gravity and similar is used to represent time/total.

Which would mean that you can get away with far simpler math if you keep track of the totals yourself(Location, Velocity, and Acceleration).   In this case your real velocity because you're dealing with speed.

So to simulate an arrow going off You're going to add a large amount to X-Velocity and Y-Velocity.   Then each game tick you going to add X-Velocity and Y-Velocity to your arrow location  X-Location/Y-Location(assume that all values can and will be negative).

To draw your Arrows tail you're you're going to base your angle on the new location and your old location for drawing.  Going to take trig and maybe some linear math depending if you're not drawing a sphere.

The fun part now is simulating acceleration.   For this we're going to have the variable X-Acceleration and Y-Acceleration,  and we're going to add them to velocity each tick.   In the case of gravity we're going to have a Positive Y-Acceleration(assuming 0,0 is the top left corner).  

Now if we're going to add friction this also becomes pretty simple to simulation, each tick we're going take X-Velocity and Y-Velocity closer to 0(with simple addition/subtraction after we've found wither velocity is negative/Positive).  

Believe or not that logic above is the logic behind calculus since you're using derivatives there, Though I'm Sure It'll piss off someone who takes math seriously(and forgot that it only exists for communication).

______________

The next thing we need to consider is force/acceleration in a direction that isn't 90 degrees.

For a pet project I want to to graph 360 points, with Sin as the X values and Cos as the Y values(Make sure you multiply by 20 or 30 or you'll just get a useless point).

You should notice that You ended up drawing a Circle.   Now with a bit of logic you'll realize that A) All the points are the same distance from the center(the 20 or 30 you multiplied by)  B) that at the 0/90/180/270 angles that that you're going to have one value of X/Y be the 20 or 30 you multiplied by and the other value be 0(which is a restatement of A).  

Which means that with some code wrangling you logical way to create a force/acceleration value(for adding) in any direction/angle.

_____________

EDIT: of course to work with this you're going to want a fixed tick(delta) if you have anything that is multiplicative, and you can not lose ANY time in your game loop

There are no such things as bugs...  Only happy accidents.
Offline nerb
« Reply #20 - Posted 2013-05-06 11:38:29 »

G'day Andre,

I recently toyed with a program that involved a ship in orbit around multiple planets. The motion was taking into account gravity, thrust, and ultimately atmospheric drag (although I didn't get around to that). It was all a bit overwhelming at the start, but it became ridiculously simple when using vector math.

So my suggestion is read up on simple vector math if you need to, and then roll your own 2D vector class. Then instead of worrying about parabolas and all that business, it just becomes a case of adding, normalising and multiplying a few vectors (which can be easily contained in a few methods of your vector class).

Then your update loop will essentially be:

1) sum all the acceleration vectors in effect: acceleration = gravity + drag;   [if you are modelling drag, which itself is dependant on velocity, otherwise acceleration = gravity and doesn't change].
2) apply the net acceleration vector to the velocity vector: velocity = velocity + acceleration * deltaTime;
3) apply the velocity vector to your arrow's position: position = position + velocity * deltaTime;
4) repeat in the next loop.

In the above acceleration, gravity, drag and velocity are vectors. deltaTime is a scalar, and position could be treated as a point. It will result in the arrow taking the nice parabolic path that you are looking for.

You just need to set your initial velocity vector prior to launch, which will be influenced by the direction the arrow is pointing in, and its total initial velocity. You would:
1) Normalise the direction vector (i.e. make it a vector in the same direction, but with a total length of 1; done by dividing both x and y by the length).
2) Multiply the normalised vector by the total initial velocity (i.e. It might have a launch velocity of 60m/s, depending on how far back the bowstring is drawn).

Anyway, hope it makes a bit of sense, I'm not the best at explaining things. But if you look into vectors a bit, you should find they make life a lot easier. Let me know if you've got any questions, or want me to dig some code out.

nerb.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!