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.

AppGameKit Classic Chat / Water Wave Physics 2d

Author
Message
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 8th Apr 2020 22:02
I am trying to create a 2D water system, it is not very complex but I have not been successful with what I have tried.

I first tried to make spring sprites to simulate waves but nothing worked
I tried to simulate the water surface with Rope Joints but it doesn't work as I wanted.

i'm trying to do something like this

fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 8th Apr 2020 23:12
I didn't have much such success with the same effect myself but I do think a shader
is the best approach. This is my attempt


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
nz0
AGK Developer
13
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Apr 2020 23:52 Edited at: 8th Apr 2020 23:53
Would have been nice to boost the built in box2D with LiquidFun. I asked about this years ago; there's enough there to make a plugin if someone wants to...
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 9th Apr 2020 00:17 Edited at: 9th Apr 2020 17:56
the shader is cool but the problem with physics will continue to exist.

I'm trying to do something like this right now



A group of rectangles that are elastic and react in a wave.
The problem with this is that I don't know how to make the water surface.
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 9th Apr 2020 00:33 Edited at: 9th Apr 2020 00:46
Would a sine curve help
where the different colours are placed at the height of the sine curve positioning by the top corner

im thinking something like this

It wont matter if the different sprites actually go below the bottom of the screen
and you shouldn't have to move them horizontally this is just a quick example
from code I previously had that I thought may help

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 9th Apr 2020 16:37
I am failing spectacularly so far in all my attempts


sine waves is a good idea and I try several things, some complex and some simple.
I tried to implement what you did, but it didn't go well.
and then I tried to think simple and this came out.

but I have no idea how I could implement physics here, and I'm sure that that incremental x will be a problem.



I went looking for tutorials and found this
https://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236
I am trying to get ideas from this and continue with the idea of ​​multiple rectangular sprites.
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 10th Apr 2020 01:36

I tried to use joints.
i think the best way to do this is using joints

It should be easier to implement physics with other objects later.
but at this moment I have a jelly effect and not water.

blink0k
Moderator
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th Apr 2020 02:36
If you could average out the position of the circles on top i think this might work
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 10th Apr 2020 04:59
that looks good with the joints brunuu but I don't understand what problem you are foreseeing
with the physics just using a sine curve ???

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 10th Apr 2020 14:20
the problem is that the character needs to get in and out of the water and water needs to react in waves according to the impact of the object
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 11th Apr 2020 00:47

it's far from perfect, but I think I'm getting there.


fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 11th Apr 2020 09:37 Edited at: 11th Apr 2020 10:16
that's great brunuu

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 11th Apr 2020 20:10
I am having trouble understanding my own concept.

I have no idea what's going on here


Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Apr 2020 00:00 Edited at: 12th Apr 2020 00:01
a little confused on what you want (same as the last challenge of yours i participated in), but:



now, do you want it to continue down? or ride the wave? the above does what i think you were after in the first post. later, it seems you wanted it to dive under the surface?

regardless, always appreciate the physics challenges you pose
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 12th Apr 2020 02:46 Edited at: 14th Apr 2020 07:15
that is very good, is more than what I have

what I'm trying to do is this

a little better than this maybe.

it has not been an easy task
blink0k
Moderator
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Apr 2020 04:31
I think you need a spring
Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Apr 2020 07:56 Edited at: 12th Apr 2020 08:25


getting closer? (my first time playing with category bits)
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 12th Apr 2020 08:36
that's pretty neat virtual nomad and here I was thinking some complex shader work be needed
Great stuff

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 12th Apr 2020 20:46 Edited at: 12th Apr 2020 20:46
well, this is better than what I was trying to do.

I don't know how it will work with the player being able to jump in and jump out.

I'm starting to think that this water system is too ambitious, maybe I have to think of something simpler, but I don't know what.
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 13th Apr 2020 03:35

is there a physics command for spring physics?
Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 13th Apr 2020 03:43
not that i know of but you see the spring-like action in my code where we can set limits on some joints. this was my first go-round for anything "springy" using native commands but it seems to have potential for real spring physics (maybe even wobbly springs, like Slinky).
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 13th Apr 2020 14:26 Edited at: 13th Apr 2020 23:49
I had an idea, blink0k spring code is great for this.
it's quite good
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 14th Apr 2020 00:33

Then I put sprites on top of each rectangle to detect collision with objects.
but the problem is that I don’t know how to smooth animation when changing the Y to start the movement.

blink0k
Moderator
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 14th Apr 2020 05:03
I pinched this from here
Not 100% sure how it works but it does. I'm thinking a savvy shader dude like janbo or fubes could pass the waterline array to the shader and draw the water.

Scraggle
Moderator
17
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Apr 2020 07:27
I found this that might help:

It looks like it's what Blink is doing but it helps to have someone talk you through the process.
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 14th Apr 2020 11:22 Edited at: 14th Apr 2020 12:10
That last code you added blink works well
well kinda until you click too low down the water

With some minor changes I don't think a shader is needed

Quote: "savvy shader dude like janbo or fubes could pass the waterline array to the shader and draw the water."

Janbo, Santman of bengismo perhaps but not sure I could but there would need a fair bit passed to the shader
an array reference I think would be preferable

I think if the splash columns was redone could possible use the sprites masking to change the effect (im prob talking something I don't understand LOL)

and my attempt at a water shader hahahahha taken from my usefull snippets that's stickied maybe thats no so useful lol

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 14th Apr 2020 20:17

this is getting really good, it's already much better than that video that I had shown


it’s so good that if it continues like this, it should be a system included in AGK
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 15th Apr 2020 03:55 Edited at: 15th Apr 2020 12:29
Drop the divers above the water

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Attachments

Login to view attachments
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Apr 2020 16:44 Edited at: 15th Apr 2020 16:47
hey if you need a verry simple vertex displacement shader(it doesn't really deserve this name) to make these rectangles into ... non rectangles.... so the top vertices of each sprite fit the vertex of their neibouring sprite creating a smooth transition you can just use the default sprite vertex shader and position or scale the vertices position attribute wich are left or right of the sprite center you get with agk_spritepos uniform.
Thats probably a really bad explanation but try streching the sprite with this:


The vertexScale uniform is a vec4 so you pass the 2D scale of the left and right vertex:
SetShaderConstantByName(ShaderID,"vertexScale", 1.0,1.1,1.0,0.8)
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 15th Apr 2020 18:31
Thanks Janbo could you please show some example code on how we would use that
shader of yours im not sure I follow

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Apr 2020 18:49 Edited at: 17th Apr 2020 14:16
@fubarpk: OK


For some odd reason the agk_spritepos uniform didn't give me any value in my tiny test demo. (bug ?)
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 18th Apr 2020 21:36
my new problem is how to implement this on a level like this.
blink0k
Moderator
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Apr 2020 00:24
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 19th Apr 2020 00:46
Quote: "my new problem is how to implement this on a level like this."

If your going to use the method without the shader you will have to modify this function

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 19th Apr 2020 04:14 Edited at: 19th Apr 2020 04:14
Quote: "If your going to use the method without the shader you will have to modify this function"

I tried to do that, but I'm having errors with the array size

I'm so sorry
but I am not understanding.
what do i need to do to use the shader here?
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 19th Apr 2020 04:48
you still need this line to start at 0
for i=0 to GetVirtualWidth()/5 //columns.length //this line
but maybe to 200
SetSpritePositionByOffset(c.id, c.x+number, 240) ///this line
where number is where you want it to start on x

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 19th Apr 2020 21:06


it's working very well but needs some polishing

blink0k
Moderator
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Apr 2020 22:05
Wow! Awesome
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Apr 2020 14:51
I love physics junk like this, it's got my interest. It looks like you have a pretty good start now. Are you wanting the object to have some buoyancy or just always sink like a lead ball? I believe spring physics would help with the initial impact of the water. A few parameters of spring stiffness and damper amount (plus weight of the object), you could come up with something that bounces out of the water. If the impact is under a certain amount of force then ignore the spring and just sink.

Does an object sink at a constant rate under water or does it accelerate? I actually have no idea.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Apr 2020 00:08

yes, it is possible, since the movement is done through the AppGameKit physics
the sprite loses speed when it comes in contact with water
Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Apr 2020 01:51
brunuu, when do we get a peek at the project(s) involving these physics exercises?
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 24th Apr 2020 03:59

I dont know.
there are still many things to think about in this project and some problems to solve
but it shouldn't be too long


this is not the only project I am doing in AGK

I have 2 projects, they are very different, but this one with all these physics systems and destruction systems is more difficult to do and that's why it has had more attention from me
fubarpk
Retired Moderator
15
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 28th Apr 2020 03:24
not sure how you went with it but I was reminded of janbos free for all water shader other day
https://forum.thegamecreators.com/thread/216713 I think with some mods might be a
better method just not sure how to make it so as you could have an entry parameter etc would need
one of the shader experts but would make it easier if producing a side scrolling game with a shader
approach

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 28th Apr 2020 21:13

I still have to learn how to work with shaders in AGK

brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 1st May 2020 03:29
I really like the final result

Xaby
FPSC Reloaded TGC Backer
13
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 2nd May 2020 11:12
I like it a lot
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2020 15:04
I like how the water has a gradient to it as well.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
haliop787
User Offline
Joined: 22nd Mar 2020
Playing: With reality.
Posted: 10th May 2020 19:51
i think adding a blur shader will make it perfect
or
make the of the water Line or box (talking about individual sprites that makes the entire water )
bottom : almost full Alpha
from bottom to 2/3 top less and less alpha and at the top much less alpha , let me show you: no blur shader really needed.
Please use this as your sprites to see the magic.

you can change the RGB values also the Alpha if needed. it will give you a much smoother Water like top for the sprites.


Nadav "Haliop" Rosenberg
Lets make the world great forever.
brunuu
2
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 22nd Aug 2020 17:27
I've been trying to implement timer-based movement so that the water speed is the same regardless of the frame rate, but I haven't been able to.



Why doesn't this work? when multiplying by FrameTime the number of pixels moved should be less
Loktofeit
AGK Developer
Gold Codemaster
11
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 22nd Aug 2020 19:01
I wish I could math as well as you all do.

To solve the problem of creating waves when an object hit the water, I would have created a 2D wave animation to play at the location of the drop.
Dunno if that's faster, slower, more efficient, less efficient, or whatever, but I do know that it requires little or no brain-hurting maths on my part.

Login to post a reply

Server time is: 2020-10-22 01:28:20
Your offset time is: 2020-10-22 01:28:20