The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+2 votes

So I'm extremely new to programming, having just followed along a tutorial on how to make a simple platformer in Godot (and taking some basic python lessons beforehand). So decided to make my own with my own assets. Unfortunately the tutorial didn't cover anything like animation or how to change the player sprite (except how to flip it).

So my problem is I found is the sprites only change when I move left or right. If I just jump, it's stays in the animation for being on the ground. And if I move and jump, but stop moving before I touch the ground, the sprite stays the same for the falling sprite. That is until I move left or right, which goes back to the on ground sprites.

I added some stuff to try and fix it but I have no idea how to tell the game to check which sprite the player is currently showing. If I knew that I have a feeling I could get it to act the way I want. The stuff I added just... makes the player always facing left.

var ballRight = preload("res://Visuals/Ball Man Idle.png")
var ballLeft = preload("res://Visuals/Ball Man Idle Left.png")
var ballJumpRight = preload("res://Visuals/Ball Man Jump Up.png")
var ballJumpLeft = preload("res://Visuals/Ball Man Jump Up Left.png")
var ballFallRight = preload("res://Visuals/Ball Man Jump Down.png")
var ballFallLeft = preload("res://Visuals/Ball Man Jump Down Left.png")

func _physics_process(delta):
        if Input.is_action_pressed("Right") and is_on_floor():
         sprite.set_texture(ballRight)
    elif Input.is_action_pressed("Left") and is_on_floor():
        sprite.set_texture(ballLeft)
    elif Input.is_action_pressed("Right"):
        if vel.y < 0:
            sprite.set_texture(ballJumpRight)
        elif vel.y > 0:
            sprite.set_texture(ballFallRight)
    elif Input.is_action_pressed("Left"):
        if vel.y < 0:
            sprite.set_texture(ballJumpLeft)
        elif vel.y > 0:
            sprite.set_texture(ballFallLeft)
    elif sprite.set_texture(ballRight):
        if vel.y > 0:
            sprite.set_texture(ballFallRight)
        elif Input.is_action_just_pressed("Jump"):
            sprite.set_texture(ballJumpRight)
    elif sprite.set_texture(ballLeft):
        if vel.y > 0:
            sprite.set_texture(ballFallLeft)
        elif Input.is_action_just_pressed("Jump"):
            sprite.set_texture(ballJumpLeft)
in Engine by (14 points)

A friend of mine that I didn't even know coding figured it out for me.

All I needed to add was a variable that would change every time left or right is pressed. If right is pressed, the variable = 1, and of left is pressed, variable = 0. With that I could tell the game how to keep track of that and fixed everything to work as I wanted.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.