Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (710) Games in Android Showcase (212) games submitted by our members Games in WIP (785) 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 8822 times) 0 Members and 1 Guest are viewing this topic.
Andre Lopes
 « Posted 2013-04-16 13:41:13 »

Hi Guys!
Well, after the almost-Success with my PacMan , 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

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

Would you guys give me some tips

tyy

Btw, i know calculus I, if that helps.

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

Search of Projectile Motion will give you all the formulas.

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.
Andre Lopes
 « Reply #2 - Posted 2013-04-16 14:19:50 »

Search of Projectile Motion will give you all the formulas.

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
I will research with that in mind
TY!!!!!
 Games published by our own members! Check 'em out!
ReBirth
 « Reply #3 - Posted 2013-04-17 02: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) * timey = startVelocity * Math.sin(theta) * time - (gravity * time ^ 2) / 2`

Andre Lopes
 « Reply #4 - Posted 2013-04-17 15: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?

ReBirth
 « Reply #5 - Posted 2013-04-18 02: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.

Wolfe

Junior Newbie

 « Reply #6 - Posted 2013-05-02 20: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.
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #7 - Posted 2013-05-02 21: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.

Agro
 « Reply #8 - Posted 2013-05-03 00: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.

pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #9 - Posted 2013-05-03 09:43:36 »

Projectiles travel in a parabola.
In a vacuum. Arrows follow flatter paths.
 Games published by our own members! Check 'em out!
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #10 - Posted 2013-05-03 10: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.

Phased
 « Reply #11 - Posted 2013-05-03 10: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.
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

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

Projectiles travel in a parabola.

Except lasers.

pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #13 - Posted 2013-05-03 12: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.
quew8

JGO Knight

Medals: 53

 « Reply #14 - Posted 2013-05-03 17: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.
Agro
 « Reply #15 - Posted 2013-05-05 02: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.

quew8

JGO Knight

Medals: 53

 « Reply #16 - Posted 2013-05-05 09: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)
Agro
 « Reply #17 - Posted 2013-05-05 16: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.

DrZoidberg

JGO Coder

Medals: 19

 « Reply #18 - Posted 2013-05-05 17: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;    }}`
lithos

Junior Devvie

Medals: 1
Projects: 1

 « Reply #19 - Posted 2013-05-06 02: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.
nerb
 « Reply #20 - Posted 2013-05-06 09: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.

 numerical (133 views) 2017-02-21 07:32:16 numerical (132 views) 2017-02-21 07:31:46 theagentd (240 views) 2017-02-18 13:42:33 theagentd (241 views) 2017-02-18 13:35:16 h.pernpeintner (1403 views) 2017-01-24 22:39:11 h.pernpeintner (1391 views) 2017-01-24 22:38:32 Galdo (1953 views) 2017-01-12 13:44:09 Archive (2019 views) 2017-01-02 05:31:41 0AndrewShepherd0 (2556 views) 2016-12-16 03:58:39 0AndrewShepherd0 (2321 views) 2016-12-15 21:50:57
 SkyAphid 39x philfrei 27x theagentd 26x Archive 25x princec 22x basil_ 21x Spasi 21x misthalu 20x Coldstream24 16x Aalhex 15x orange451 14x dime26 11x Riven 10x wessles 10x SHC 9x KaiHH 9x
 List of Learning Resourcesby elect2016-09-09 09:47:55List of Learning Resourcesby elect2016-09-08 09:47:20List of Learning Resourcesby elect2016-09-08 09:46:51List of Learning Resourcesby elect2016-09-08 09:46:27List of Learning Resourcesby elect2016-09-08 09:45:41List of Learning Resourcesby elect2016-09-08 08:39:20List of Learning Resourcesby elect2016-09-08 08:38:19Rendering resourcesby Roquen2016-08-08 05:55:21
 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