Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NotAGoat |
First of all, i’d like to pologize for my bad english
Im doing the godot tutorial and i found a problem in the part where it teaches you how to flip your animation horizontally and vertically.
Whenever you try to make the player going both down and to some of the sides, the sprite flips vertically again, making it going down but pointing up at the same time.
Is there anyway i can fix that? Here is my code so far.
extends Area2D
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
func _ready():
screen_size = get_viewport_rect().size
# Called when the node is added to the scene for the first time.
# Initialization here
pass
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass
export var speed = 400 #vel em pixel/segundo
var screen_size #tamanho da tela
func _process(delta):
var velocity = Vector2() # The player's movement vector.
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
if velocity.x != 0:
$AnimatedSprite.animation = "right"
$AnimatedSprite.flip_v = false
#See the note below about boolean assignment
$AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
$AnimatedSprite.animation = "up"
$AnimatedSprite.flip_v = velocity.y > 0