0 votes

So, Im pretty new to Godot and Im making a Top Down game like Zelda except I want my sprite to be able to look only to left or right. I have that setup but my problem is that when I walk left and stop the idle animation is facing right. Same if Im facing left and going up and release left my character switches back to right, like it prefers to face right when going up or down. I know I have to store my direction in a variable and then tell the game to face that stored direction or something similar. Im using godot for only like a month and need help with this. If you find a tutorial or a guide on how to do it please tell me. Or you can tell me yourself. If you need any more information like screenshots or code please let me know.

Thanks in advance :)

Godot version 3.2.2.stable.official
in Engine by (20 points)

1 Answer

0 votes

Well I dont know how you have written this at the moment but I assume you have an animated character set up? I will assume below that there is a character with four animations which i will call AniLeft, AniRight, AniUp, AniDown. Obviously you will need to change it to suit what you have named your animations.

Func process(delta):
var vel = vector2.zero
if input.isactionpressed("uileft"):
vel.x += 1
if input.is
actionpressed("uiright"):
vel.x -= 1
if input.isactionpressed("uiup"):
vel.y -= 1
if input.is
actionpressed("uidown"):
vel.y += 1
moveandslide(vel.normalized() * 100)
personalAnimationControl(vel)

func personalAnimationControl(vel)
if vel.x > 1:
$"AnimatedSprite".play("AniRight")
elif vel.x < 1:
$"AnimatedSprite".play("AniLeft")
elif vel.y > 1:
$"AnimatedSprite".play("AniDown")
elif vel.x < 1:
$"AnimatedSprite".play("AniUp")
else:
$"AnimatedSprite".stop
$"AnimatedSprite".frame = 0

so the above shouldnt cause the problem you are seeing at least but I dont know how different that is from your code?

by (99 points)

Hello,

Im sorry I didn't put any more information. Im using an AnimationPlayer and my character has only one running animation and then I flip the sprite even though its an rpg. I like this kind of style. And my movement is setup with an input_vector like this:

func _physics_process(delta: float) -> void:
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
input_vector = input_vector.normalized()

(of course I do have the lines indented but it doesnt show here)

if input_vector != Vector2.ZERO:
    animPlayer.play("Walk")
else:
    animPlayer.play("Idle")

I know this is a little weird to do a top down game like this so sorry :)

again if you need more information just tell me

Hey update:

Im dumb... My sprite flipping script had a If and else. but i changed else with elif and now it fixed every problem i had. Thanks for your help!

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 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 webmaster@godotengine.org with your username.