Page 1 of 1
icantswim.lua - Mega Man-like water (v1.0.2)
Posted: Sun Aug 08, 2021 3:54 pm
by cold soup
icantswim.lua is a library that lowers a player's gravity when they go underwater (via water boxes, currently doesn't affect underwater sections), instead of putting them in a swimming state. Essentially, Mega Man water physics applied to Mario. Includes adjustable values for a player's jump height, fall speed, and run speed in water, and toggleable splash and bubble effects.
Note that this library is not compatible with multiplayer at the moment. (X2 characters are partially supported)
Please report any bugs you find, I'm pretty new to Lua so any feedback would be appreciated!
EXAMPLE:
DOWNLOAD:
CREDITS:
Thanks to RandomTalkingBush on the Spriters Resource for ripping the splash and bubble sprites
Thanks to KBM-Quine#6602 on Discord for discovering how to enable underwater physics for NPCs
Thanks to MrDoubleA#3124 for fixing an issue where NPCs that use player defines don't work properly
Re: icantswim.lua - Mega Man-like water
Posted: Sun Aug 08, 2021 7:15 pm
by SuperAlex
Wow. The splash effect would remember me of the SMM2 SMW Water.
Re: icantswim.lua - Mega Man-like water
Posted: Sun Aug 08, 2021 9:44 pm
by Murphmario
This is really cool! Hope sometime in the future you can make this compatable with the SMBX2 characters, especially Mega Man for obvious reasons.
Re: icantswim.lua - Mega Man-like water
Posted: Mon Aug 09, 2021 12:05 am
by Blake Izayoi
This is incredibly awesome. I'd expect to see this in a few levels in the future! Fantastic work.
Re: icantswim.lua - Mega Man-like water
Posted: Mon Aug 09, 2021 2:39 pm
by ElTipsta
This is fantastic, thanks for this

Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Fri Aug 13, 2021 7:06 pm
by cold soup
Minor bugfix update, I made it so that water boxes don't ignore if their layer is hidden and I improved the way bubbles despawn.
Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Tue Aug 17, 2021 1:31 am
by MECHDRAGON777
Reminds me of how Samus behaves in water without the Gravity Suit.
Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Fri Aug 27, 2021 2:47 pm
by MrDoubleA
A lovely little script, although it does take a bit of editing to have it not break other scripts that modify the defines (such as the X2 characters or clear pipe cannons).
Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Fri Sep 03, 2021 6:08 am
by ElTipsta
ok i've tried to put this into a level and i can't seem to get it to work.
i've tried using enjl's how to use guide in the pinned thread but it's just not working.
interestingly i even tried modifying it a bit and was able to get the intended physics placed outside of the water but not in it (kinda like zerogravity).
how are you supposed to make it compatible?
Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Fri Sep 03, 2021 7:52 am
by Marioman2007
ElTipsta wrote: ↑Fri Sep 03, 2021 6:08 am
ok i've tried to put this into a level and i can't seem to get it to work.
i've tried using enjl's how to use guide in the pinned thread but it's just not working.
interestingly i even tried modifying it a bit and was able to get the intended physics placed outside of the water but not in it (kinda like zerogravity).
how are you supposed to make it compatible?
1) Are you loading the library?
2) Are you testing this underwater?
Re: icantswim.lua - Mega Man-like water (v1.0.1)
Posted: Mon Sep 06, 2021 5:03 pm
by cold soup
ElTipsta wrote: ↑Fri Sep 03, 2021 6:08 am
ok i've tried to put this into a level and i can't seem to get it to work.
i've tried using enjl's how to use guide in the pinned thread but it's just not working.
interestingly i even tried modifying it a bit and was able to get the intended physics placed outside of the water but not in it (kinda like zerogravity).
how are you supposed to make it compatible?
are you using water boxes? the water physics don't work if you set a section to underwater.
Re: icantswim.lua - Mega Man-like water (v1.0.2)
Posted: Sat Oct 02, 2021 5:46 pm
by cold soup
Another bugfix update, this one's more major. This update fixes issues related to NPCs that use player defines, such as Launch Barrels. X2 character support should be better, although I still have to modify a few things before they become fully supported. Massive thanks to MrDoubleA for providing a fix to these issues!
Re: icantswim.lua - Mega Man-like water (v1.0.2)
Posted: Thu Apr 13, 2023 2:29 pm
by DisasterMaster
I noticed that icantswim affects Dolphins and SMW Orange Floating Platforms similarly to the player, but other such aquatic NPCs like Bloopers and Cheep-Cheeps are not affected.
How do you make Dolphins and Floating Platforms unaffected?
Here is an example (the outlined area is water; the crate is a Platform and Shark is the short-jump Dolphin):

Re: icantswim.lua - Mega Man-like water (v1.0.2)
Posted: Mon May 08, 2023 11:30 pm
by cold soup
DisasterMaster wrote: ↑Thu Apr 13, 2023 2:29 pm
I noticed that icantswim affects Dolphins and SMW Orange Floating Platforms similarly to the player, but other such aquatic NPCs like Bloopers and Cheep-Cheeps are not affected.
How do you make Dolphins and Floating Platforms unaffected?
Here is an example (the outlined area is water; the crate is a Platform and Shark is the short-jump Dolphin):
sorry it took a while for me to see this, but i think i know the issue. (long-winded technical explanation below)
the way the library works is that it stores references to every water box in the level in a table, makes them hidden, then handles players and npcs colliding with them manually. what the library does is check if any NPCs are intersecting with any water boxes, it sets a memory offset of that NPC to a specific value that makes them act as if they're underwater. while this works for most NPCs, it appears dolphins and floating platforms don't use that memory offset and only interact with water if they themselves detect they're intersecting with any non-hidden water boxes. and since icantswim.lua hides every water box once the level starts, they can't interact with any water boxes.
unfortunately since this is caused by a quirk with how those NPCs work, i don't know if i can fix that issue without rewriting the entire library. however, you could modify waterleaper.lua (the dolphin's AI script) to make it so that the getOverlappingBoundWater() at line 77 doesn't check if a water box is hidden, then put it in your episode/level folder. same for npc-391.lua (the floating platform's script), except you'd remove the if statement at line 65.