I started a new game to learn about platforms.
Well, how do I make it so my platformer can swim?
So I make it a sprite called water
Add something like he falls down a little deeper every second when touching the water.
Pressing an up button would make him swim upward.
Pressing a down button would make him swim downward.
Left and Right would still be side to side.
How would I code this?
Maybe water won't have any behavior.
Maybe set the player gravity to (normalgravity/2) when touching the water? I think this will possibly make him fall slowly.
Maybe something like increase the y by vector 10 or something so it's like he swims upwards.
Is there a better way to code this?
Develop games in your browser. Powerful, performant & highly capable.
Actually you don't have to do anything complicated. You can just set a condition where, every tick that player is not pressing up, character y +2, or a number that you prefer. That way, it slowly sinks only if the player is not pressing up which means it is swimming up. For down, left and right, just set the movement to the appropriate x and y coordinates. Just remember to set your platformer control to off when it is in collision with the water object.