2D (not 3D) Platformer game add swimming

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rodell2020

[Godot 3.2 or 3.4.4 windows 10 ]
https://www.youtube.com/c/BornCG/playlists (Godot 3 tutorial series)
I am making a platformer game so I would like to make it so that the player is walking on the platform comes to a water section (swims across ) then walks on the next platform
(and maybe while under water collects coins etc.)

:bust_in_silhouette: Reply From: Pomelo

Sorry if this feels harsh but it is not the intent. You are not really asking anything. Try to be more specific and tackle one problem at a time. For example, what do you want “swimming” to be in your game? do you want the character to be able to move in all directions under the water?, do you want it to be still when no input is detected? do you need help with detecting when the player is in the water, in order to change some animations?

I could go on, but there is tons of stuff that could be done. So tell me, and I will try to help!

Lets try this
character walks across platform hits water swims to the other platform and then walks across it etc…

while in the water the character can look for and collect coins etc.
if the character dose not swim he sinks to the bottom (the character dies.)

if he is in the water for more than 5 min he dies

rodell2020 | 2022-06-12 22:05

Again sorry but too broad of a question. I am telling you this, so in the future you can get better awnsers. I dont know how much you know, and with what you need help, and of course i cant write you the whole code of everything you want as I envition it.

For example, collecting coins. What do you need help with there? Do you know about area detection, queue_free, saving score in a var?

Another thing, why is it important that the player starts and ends on a platform in your question. do you need help with the transition? like when the character is close to the border to have a climbing animation?

I would sugest that you just start by making the player to move in the water. You need to first know, when the player is ocupying water. To do this I would suggest having an Area2d on the water that sends a signal to the player when the player enteres and exits the area. Once that is done, write a var in the player called swimming that becomes true or false when recieving this signals. Then in the movement code, check if player is swimming, and do the correct changes. This includes a lower gravity value, and the ability to go upward.

Pomelo | 2022-06-12 23:06

:bust_in_silhouette: Reply From: CassanovaWong

I would just use a weaker gravity than whatever you’re using while the character is on land. And I’d use a position vector, like an anchor… And, then have a script make the character rise if it goes too far below the position vector and then fall if it is too far above. If you use small numbers it should appear as the character is bobbing up and down.

The rest of the stuff, should be pretty similar to platform direction control and item detection, etc. … I’m assuming you’ve got that part…