Top-down liquid (water) physics simulation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
dusoft
Party member
Posts: 715
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Top-down liquid (water) physics simulation

Post by dusoft »

Hello,

can anyone point me to a good lib for simulating liquid, but top down? I have checked the wiki, there are some outdated libs that even throw 404s. I have checked the awesome love2d list, but that does not really have this kind of physics.

Also, I need to work with polygons (probably going to use either older v of HardonCollider or Strike lib, both work well), but I still need help with physics.

Basically I just need to simulate very simple physics for entities moving in water (such as boats etc.).

(PS: I know can probably simulate this via love.physics, but then I would start from the beginning. If there was an existing library, I would prefer using that.)

UPDATE: I am trying to use love.physics and got some primitive concepts working. I do not understand what I should do regarding angles. E.g. boat is always moving to front (if LinearVelocity goes negative). But front means different directions based on different angle. So how do I calculate LinearVelocity X,Y based on this angle? If I don't do it, such boat will always just move up (negative LinearVelocity y), even if it faces down (e.g. decimal angle 180).
User avatar
pgimeno
Party member
Posts: 3691
Joined: Sun Oct 18, 2015 2:58 pm

Re: Top-down liquid (water) physics simulation

Post by pgimeno »

dusoft wrote: Tue Apr 04, 2023 11:02 amSo how do I calculate LinearVelocity X,Y based on this angle? If I don't do it, such boat will always just move up (negative LinearVelocity y), even if it faces down (e.g. decimal angle 180).
Unless I'm misunderstanding something:

Code: Select all

body:setLinearVelocity(math.cos(angle)*speed, math.sin(angle)*speed)
User avatar
dusoft
Party member
Posts: 715
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Top-down liquid (water) physics simulation

Post by dusoft »

pgimeno wrote: Tue Apr 04, 2023 5:46 pm
dusoft wrote: Tue Apr 04, 2023 11:02 amSo how do I calculate LinearVelocity X,Y based on this angle? If I don't do it, such boat will always just move up (negative LinearVelocity y), even if it faces down (e.g. decimal angle 180).
Unless I'm misunderstanding something:

Code: Select all

body:setLinearVelocity(math.cos(angle)*speed, math.sin(angle)*speed)
Unfortunately, no, that does not work. It works, but the polygon "front" has to face right.

I would prefer using body:applyForce(xf, yf) instead as setting Velocity directly defeats the purpose, but I guess I could work with this. Thanks!
Last edited by dusoft on Tue Apr 04, 2023 6:01 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3691
Joined: Sun Oct 18, 2015 2:58 pm

Re: Top-down liquid (water) physics simulation

Post by pgimeno »

Hard to give any further advice without any code to look at, sorry.
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: Top-down liquid (water) physics simulation

Post by darkfrei »

Are you need the physics of hovercraft? It goes not where it's directed, but where it has the speed as rest on inertia.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
dusoft
Party member
Posts: 715
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Top-down liquid (water) physics simulation

Post by dusoft »

darkfrei wrote: Tue Apr 04, 2023 8:26 pm Are you need the physics of hovercraft? It goes not where it's directed, but where it has the speed as rest on inertia.
No, I would like to use body:applyForce for speeding up a boat. E.g. holding up key applies force continuously by the physics class of LOVE. I am now a bit stuck how to represent this using this function.
User avatar
knorke
Party member
Posts: 275
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Top-down liquid (water) physics simulation

Post by knorke »

Use the same principle.
You have a vector expressed as the boat's direction and the boat's speed.
You want to express the vector as two linear components.
To do this you use sin and cos.

Code: Select all

body:applyForce(math.cos(angle)*speed, math.sin(angle)*speed)
This will not give you boat physics more spaceship physics but you can tweak it from there.
For example adding friction and maybe the ship's rudder should only turn the boat when it is moving forward etc
User avatar
dusoft
Party member
Posts: 715
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Top-down liquid (water) physics simulation

Post by dusoft »

knorke wrote: Thu Apr 06, 2023 12:11 am Use the same principle.
You have a vector expressed as the boat's direction and the boat's speed.
You want to express the vector as two linear components.
To do this you use sin and cos.

Code: Select all

body:applyForce(math.cos(angle)*speed, math.sin(angle)*speed)
This will not give you boat physics more spaceship physics but you can tweak it from there.
For example adding friction and maybe the ship's rudder should only turn the boat when it is moving forward etc
OK, I am going to try that. I though I wouldn't have to keep speed variable manually as the physics module takes care of that (getLinearVelocity), but alright. Regarding friction - I have already solved this by damping.

On an unrelated note: I really think the physics module should be simplified, all these concepts (separate body, shape etc.) are hard to grasp first even for a programmer with 25+ years of experience (not in games, though). I am getting through, though.
User avatar
knorke
Party member
Posts: 275
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Top-down liquid (water) physics simulation

Post by knorke »

ah, "speed" is just bad naming because I copypasted.
It is actually a constant, a better name would be "thrustPower".
User avatar
dusoft
Party member
Posts: 715
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Top-down liquid (water) physics simulation

Post by dusoft »

knorke wrote: Thu Apr 06, 2023 9:21 am ah, "speed" is just bad naming because I copypasted.
It is actually a constant, a better name would be "thrustPower".
Well noted and makes more sense.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests