Godot Version
4.2.2
Question
Hello! Im not very experienced in programing yet and ivebeen all night trying to make a top down movement, but simply wont work, im so close to make it funcional but now my problem is that the character simply wont stop walking.
pls help u_u
heres my code
extends CharacterBody2D
var speed = 150
var run_speed = 230
var is_running = false
var is_moving = false
@onready var animation = $AnimatedSprite2D
func _ready():
pass
func _physics_process(delta):
# Movimiento
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
is_running = Input.is_action_pressed("ui_back")
var current_speed = speed
if is_running:
current_speed = run_speed
if velocity != Vector2.ZERO:
velocity = velocity.normalized() * current_speed
move_and_slide()
if abs(velocity.x) > abs(velocity.y):
if velocity.x > 0:
if animation.animation != "walk_right":
animation.play("walk_right")
else:
if animation.animation != "walk_left":
animation.play("walk_left")
else:
if velocity.y > 0:
if animation.animation != "walk_down":
animation.play("walk_down")
else:
if animation.animation != "walk_up":
animation.play("walk_up")
elif Input.is_action_just_released("move_down"):
animation.play("default_down")
elif Input.is_action_just_released("move_up"):
animation.play("default_up")
elif Input.is_action_just_released("move_right"):
animation.play("default_right")
elif Input.is_action_just_released("move_left"):
animation.play("default_left")
animation.stop()