icantswim.lua - Mega Man-like water (v1.0.2)

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

icantswim.lua - Mega Man-like water (v1.0.2)

Postby cold soup » Sun Aug 08, 2021 3:54 pm

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:
Spoiler: show
Image
DOWNLOAD: CREDITS:
Spoiler: show
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
Last edited by cold soup on Sat Oct 02, 2021 5:43 pm, edited 4 times in total.

SuperAlex
2025 Egg Hunter
2025 Egg Hunter
Posts: 226
Joined: Mon Nov 02, 2020 3:02 pm
Flair: Spriting
Pronouns: He/Him
Contact:

Re: icantswim.lua - Mega Man-like water

Postby SuperAlex » Sun Aug 08, 2021 7:15 pm

Wow. The splash effect would remember me of the SMM2 SMW Water.

Murphmario
2025 Egg Hunter
2025 Egg Hunter
Posts: 2389
Joined: Fri Dec 20, 2013 7:07 pm
Pronouns: he/him

Re: icantswim.lua - Mega Man-like water

Postby Murphmario » Sun Aug 08, 2021 9:44 pm

This is really cool! Hope sometime in the future you can make this compatable with the SMBX2 characters, especially Mega Man for obvious reasons.

Blake Izayoi
Volcano Lotus
Volcano Lotus
Posts: 598
Joined: Sun Feb 23, 2014 1:55 pm
Flair: Sakuya's Husband
Pronouns: He / Him
Contact:

Re: icantswim.lua - Mega Man-like water

Postby Blake Izayoi » Mon Aug 09, 2021 12:05 am

This is incredibly awesome. I'd expect to see this in a few levels in the future! Fantastic work.

ElTipsta
Lakitu
Lakitu
Posts: 485
Joined: Fri Dec 20, 2013 3:16 pm
Pronouns: she/her

Re: icantswim.lua - Mega Man-like water

Postby ElTipsta » Mon Aug 09, 2021 2:39 pm

This is fantastic, thanks for this :)

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby cold soup » Fri Aug 13, 2021 7:06 pm

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.

MECHDRAGON777
Pink Yoshi Egg
Pink Yoshi Egg
Posts: 6422
Joined: Fri Dec 20, 2013 6:40 pm
Flair: Nuclear Queen of Reversion.
Contact:

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby MECHDRAGON777 » Tue Aug 17, 2021 1:31 am

Reminds me of how Samus behaves in water without the Gravity Suit.

MrDoubleA
Edward
Edward
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby MrDoubleA » Fri Aug 27, 2021 2:47 pm

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).

ElTipsta
Lakitu
Lakitu
Posts: 485
Joined: Fri Dec 20, 2013 3:16 pm
Pronouns: she/her

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby ElTipsta » 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?

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 544
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby Marioman2007 » Fri Sep 03, 2021 7:52 am

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?

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

Re: icantswim.lua - Mega Man-like water (v1.0.1)

Postby cold soup » Mon Sep 06, 2021 5:03 pm

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.

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

Re: icantswim.lua - Mega Man-like water (v1.0.2)

Postby cold soup » Sat Oct 02, 2021 5:46 pm

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!

DisasterMaster
Blooper
Blooper
Posts: 164
Joined: Fri Jan 31, 2020 10:01 pm

Re: icantswim.lua - Mega Man-like water (v1.0.2)

Postby DisasterMaster » 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):
Image

cold soup
Swooper
Swooper
Posts: 73
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: they/she
Contact:

Re: icantswim.lua - Mega Man-like water (v1.0.2)

Postby cold soup » Mon May 08, 2023 11:30 pm

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):
Image
sorry it took a while for me to see this, but i think i know the issue. (long-winded technical explanation below)
Spoiler: show
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.


Return to “LunaLua”

Who is online

Users browsing this forum: Lungi and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari