Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Game Design Theory / Water Drag and Buoyancy Physics

Author
Message
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 27th May 2011 05:44
Hey im working on a remake of Angry Birds called Pissed Off Penguins. Basically rather than launching a bird into the air, you are shooting a penguin at a downward angle into the water and he floats back up based on buoyancy. I need some SIMPLIFIED physics theories and formulas to create semi-realistic drag and buoyancy, and also I need the physics to simluate an angled "leap" from the water and back down (so gravity and perhaps air drag).

I googled these topics but the formulas were way complicated, can someone dumb it down to high school junior level?

Thanks!!


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th May 2011 09:40 Edited at: 27th May 2011 10:52
Buoyancy is basically the difference in pressures acting on the top of the object and from the bottom of the object. The force acting on the top or bottom of the object is equal to the pressure times the surface area. So by subtracting the top and bottom forces, you will get the net vertical (as if dropping an object straight down into water) force.

Ok, I sort of ignore the standard equations. This example doesn't account for the mass of the object so it's really a faked buoyancy effect.




Melancholic
14
Years of Service
User Offline
Joined: 26th Nov 2009
Location:
Posted: 28th May 2011 12:54
If i understood you right, then the penguins goes into the water, then returns to the surface? A logic way of doing this would seem to be to use a parabola for the shape of the penguins path, you can create a parabolic shape with the function y=A*x^2+B*x+c. Cant seem to find a page which will explain just the basics you would need to know, here is the best i found though http://www.intmath.com/plane-analytic-geometry/4-parabola.php

This would also make the game very systematic with moves being able to be repeated accurately and the destination of the penguin could also be guessed


I can count to banana...
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th May 2011 20:38
ya ive spent a lot of time working with parabola's in my last 2 math classes (algebra 2 and trig w/ college algebra) but i have never seen this terminology before. one equation I am used to is the equation y = (A*x^2 + h) + v where A is the "slope" and direction (High -> High or Low -> Low) or the parabola, NEGATIVE h is the horizontal shift of the parabola, POSITIVE v is the vertical shift of the graph.

the other equation for a parabola I have seen is y = a*x^2 + b*x + c this equation allows the use of the quadratic formula to calculate both the vertex (high/low of the graph) and the zeroes. the equation x = (-b)/(2a) yields the x value of the vertex (plug it back in to find the y). and if you modify the equation to be (-b +- sqrt(b^2 - 4ac))/(2a) it will then calculate the x values for the zero(es).

the question remains, how can I use the position of one zero (0,100 in DarkGDK) and the angle of the shot to create a complete parabola equation? and btw Phaelax im on vacation and my uncle's firefox cant open your snippet so i will read that when i get home.


Melancholic
14
Years of Service
User Offline
Joined: 26th Nov 2009
Location:
Posted: 28th May 2011 23:39 Edited at: 28th May 2011 23:40
In the case of angry birds here is how i would do it



there i have two points where the bird will travel through, using these two points i would then find the equation of the parabola. When the penguin is released, i would alter the x value of the penguin, then find the y value that correlates to using the equation found earlier

[EDIT] Of course you also know the variables x and y in the picture


I can count to banana...
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th May 2011 07:07
that works for angry birds, in which you pull the bird BACK, but in my game you select the angle and power at which you launch (keeping the mouse AHEAD of the starting point). So the only things i know and could use to calculate a parabola are: the start point (0,100), the angle of the shot, and the power of the shot (200 max).

originally i tried to simply start with the penguin traveling in a straight line following the slope of the shot, and have him angle upwards a tiny bit each iteration of the main loop, thus SIMULATING a parabola, so if i could use this information to find the X value at which the penguin would cross the line of y = 100 (remember that in DarkGDK the top of the screen is y=0 and the bottom is y=600) then i could use algebra to calculate a parabola in the form of y = (A*x^2 + h) + v.

So to summarize, I need to figure out that with a starting angle of S, a power of P, and an upward change of C degrees per iteration, at what X value would the penguin return to the same altitude from which he was fired.


bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 30th May 2011 15:57 Edited at: 30th May 2011 15:58
I'd probably take a simpler approach.

Figure the penguin's x and y velocity based on the numbers entered.

Calculate the panguin's gravity on each loop which affects his acceleration toward earth.

Add some largish value to the y velocity away from earth proportional to how deep in the water he is and finally, angle the penguin in the direction he's moving.

If you need to figure out where he's going to be then you'll have to pull out the fancy math, but otherwise, you're working too hard.

[center]Official TGC President elect.
Pwning newbs since 2002.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 31st May 2011 04:58
ya thats sortof what I was doing only even simpler. im using DarkGDK so i just figured out the angle of the shot, aimed the bird, moved him, rotated him like .2 degrees upwards, and repeated. that works fine but I would really like realism.


Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Jun 2011 03:20 Edited at: 2nd Jun 2011 03:22
Okay, so... the bird has position <x,y>, velocity <Vx,Vy>, starting speed d, and angle a. When the bird is launched, you set the velocity to: <cos(a)*d,sin(a)*d>

then, if he's under the water, I'd set the x and y velocity as such:
Vx=Vx-drag*Vx
Vy=Vy+bouyancy
[edit] or Vy=Vy+bouyancy*abs(y)[/edit]

I figure if the x velocity is 0, then he shouldn't be decelerating, and if he's going at the speed of light, his speed will be decreasing a ton. Hence, Vx-drag*Vx. As drag increases, he slows down faster. (note how this is similar to Vx=Vx*drag)

Then, for the bird's rotation, just pass the bird's velocity into the atanfull command.


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 4th Jun 2011 01:52 Edited at: 4th Jun 2011 01:54
sounds simple enough, but if i repeatedly say:

Vx = Vx-drag*Vx

then wouldnt that vastly INCREASE his horizontal velocity? Or am i misreading this?

Edit:

or is drag supposed to be a number <1? if that is the case then why not just say Vx = Vx*(1-drag) ?


JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 4th Jun 2011 04:18
At the risk of getting my proverbial hands slapped; here is the source for an old DOS game that used to ship with DOS 5.0 back in the day. It's called "Gorillas" (bringing back some memories of you old-timers?) and it has the same type of functionality that you are looking for.

While I can't explain the code, the premise is this: Each player gorilla throws bananas at each other. At launch, the game takes the player's X,Y coordinates, Angle of throw and velocity to calculate an angle of trajectory (considering wind-drag/gravity).

Sounds exactly like what you are looking for (except maybe inverted). I found this code online - not sure where - but back in the early 90's it was shipped with MS-DOS as a sample QBasic program.

Google "Gorillas QBasic" and you can find the full source file if you want it as a reference because this snippet only shows the relavent function: PlotShot()



I hope this helps!

JTK
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 4th Jun 2011 05:08
im not familiar with QBasic so some of the code is throwing me off...can someone please translate this into pseudo-code (ordinary sentences explaining what each code block/line does)? Thanks!


JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 15th Jun 2011 17:21
I'm sorry for the late response (I have been very busy lately), but I have posted a Code Snippet with a GDK example for your reference.

The snippet handles both Gravity (bouyancy) and wind...

Check out the snippet, as I think it will provide you with some useful insight.

I hope this helps,

JTK
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Jun 2011 23:27
(I think JTK has a great example but I'll just clear up what I meant for future reference xD)

Quote: "sounds simple enough, but if i repeatedly say:

Vx = Vx-drag*Vx

then wouldnt that vastly INCREASE his horizontal velocity? Or am i misreading this?

Edit:

or is drag supposed to be a number <1? if that is the case then why not just say Vx = Vx*(1-drag) ?"


yes. iterating Vx=Vx-drag*Vx only shows regular/expected behavior when 0<drag<1. if drag was greater than one the velocity would keep switching directions, and if drag was less than 0 it would accelerate rapidly. You can simplify it to Vx*(1-drag) regardless of the value of drag. All I meant was that the equation:
Vx-Vx*drag
is more intuitive, and easier to be understood, because you're saying "the greater Vx is, the greater the deceleration"


Why does blue text appear every time you are near?

Login to post a reply

Server time is: 2024-04-25 08:00:06
Your offset time is: 2024-04-25 08:00:06