Character movement on the diagonal platform

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

I’m developing a game for learning with free assets, the game is a 2D platform, the character movement tutorial in the godot documentation and internet tutorials serve well to move and jump the character horizontally and vertically, but I want when the character is going up diagonally use the “movement” sprite but because of the code that activates gravity the character is going down alone and activating the descent sprite when I go up it activates the jump sprite.

enter image description here

the image above shows the character descending and with the falling sprite activated I just want him to walk on the platform.

I’m following godot’s movement tutorial Kinematic character (2D) — Godot Engine (stable) documentation in English

:bust_in_silhouette: Reply From: RandallCurtis

Hard to say without seeing your animation code, but generally you would only set a jumping or falling animation when is_on_floor() is false. The logic would be something like:

if !is_on_floor():
   if velocity.y > 0:"falling")

The character sliding down the slope on his own is a little more advanced since you would have to make use of the move_and_slide_with_snap() function. This keeps the character “snapped” to the floor even when gravity is being applied. Just note that you would also have to “unsnap” the player when jumping. For a tutorial, check out this Pigdev video.