# Physics objects go swimming!

Post your own tutorials, guides and demos.

### » Mon Jan 05, 2009 4:20 am

I've made water that can combine with physics objects for buoyancy and displacement. Nothing very complicated - objects are pushed upwards based on their individual buoyancy, and the water level rises based on the number and size of objects in the water. Both of these scale for how much of the object is submerged.

Anyone who wants to use this is most welcome. I just added the water as a part of my game - though if I'd realised how annoying it would be to implement, I probably wouldn't have done it. Construct is bound to get inbuilt physics water sooner or later!

Still to do:

- Make scaling more accurate for ellipses (if motivated enough).
- Slow down objects to simulate water drag (when Get Force is added).

http://dl.dropbox.com/u/906550/Construct/water.cap

B
5
S
2
G
4
Posts: 113
Reputation: 2,101

### » Mon Jan 05, 2009 7:36 pm

Nice demo! It runs really slow on my computer when an object is overlapping the surface of the water though. But on a faster computer I bet it's fine.

Anyway, I just wanted to mention also that you don't need to make a loop for each event. You can place all of your box floating and displacement code into one loop like so:

This still works just fine. You could make a second loop for the circle the same way, and have just two loops instead of the ten loops you have now.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

### » Mon Jan 05, 2009 10:24 pm

So that's how it works! I started out trying to do that, but kept getting anomalous results (eg, when something fell into the water, all of the water sprites would gain height, instead of just the relevant one). Judging by your example, I must have been putting the loop condition in the wrong order.
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

B
1
S
1
G
1
Posts: 8
Reputation: 591

### » Wed Mar 16, 2011 10:20 am

Oh, sure.

I couldn't find the original version, so here's one with some bonus cruft (like water displacement). The events are grouped, though, so you can definitely find the buoyancy stuff.

http://dl.dropbox.com/u/906550/Construct/water.cap
B
5
S
2
G
4
Posts: 113
Reputation: 2,101