frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How to create water buoyancy in Flowlab?

edited July 25 in How To
I've had this idea for a mobile game, and I tried to make it in other game engines and even attempted to code it (which I don't know how to), but basically I'm trying to make it so 75% of the screen all the way to the bottom is water, and the top 25% is air, and I want an object to float on top of the water and when you tap and hold it'll sink until you let go, and when you let go I want the object to shoot back up to the air level and out of the water.

Think of it like in real life, if you took a barrel to an ocean and forced it under water to the bottom and let go, it would shoot itself back up and out of the water and fall back down to the surface of the water, I'm trying to recreate this.

I’ve been using FlowLab on and off for I think 3 years now, and if I could get this to my liking I’d finally buy premium and upload this to the Play Store finally making it my first application on the store.

Comments

  • How I did water physics and how other users have done it was to set the game gravity to zero and use the motor behavior block to dictate the gravity of a specific object (always--number--y motor). This can be used to give each object a different gravity, and also enables changing "gravity" values. Gravity above water can be a large negative value while gravity in water could be a small negative value (to sink slowly) or positive value (to float).
    The best way is to use a proximity sensor for the water object (with a distance making a circle slightly larger than the sprite being used), an always block, two logic gates (AND, NAND), three number blocks, and the motor block. Connect the proximity sensor and always block each to both logic gates, next have the AND logic gate connected to one number value (this will be the water gravity) and set it to a value such as 10, and have the NAND logic gate connected to the second number value (this will be the air gravity) set to a value such as -30. Then connect the first two number blocks to the "set" input of the third, and connect the always block to the "in" input of the new number block. Finally connect the output of the third number block to the "y" input of the motor block.
    This is the most effective and reliable method I know about. I have tried using collisions with the surface of the water, but this has caused floating in air on several occasions. I apologize if I was overly wordy, but I hope this helps.
  • edited July 26
    @H-man Thank you so much, I’ll try this asap.
  • Because you want to copy paste?

    I have an example game but it's not exactly what he said. Just take a look at my profile.
  • edited July 26
    @Latif3 You can copy paste in FlowLab? How do you do that?
  • Uh, yeah, in the behavior screen. You can select, copy and paste. Selection tool is next to the zoom buttons, copy button appears after selecting.

    You can paste by clicking on an empty space in the behavior screen, it will show a popup to paste. If that doesn't work you can also click import and paste it on the text box (Ctrl+V), and click OK.
  • edited July 26
    Followed what H-Man said and I got it! Thanks :)
Sign In or Register to comment.

flowlab.io

| make games in your browser
@ 2017 Flowlab.io, All rights reserved.

Contact us

Get In Touch