Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cryothenir |
extends KinematicBody2D
var velocity: Vector2 = Vector2()
const friction = 100
const acc = 70
const walk_speed = 150
const run_speed = 600
var is_running = null
func _process(delta):
move()
move_and_slide(velocity)
func move():
velocity = Vector2()
if Input.is_action_pressed("ui_left"):
velocity.x = -walk_speed
$AnimatedSprite.play("Left_Walk")
elif Input.is_action_pressed("ui_left") and Input.is_action_pressed("run"):
velocity.x = -run_speed
$AnimatedSprite.play ("Left_Run")
elif Input.is_action_just_released("ui_left"):
$AnimatedSprite.play("Left_Idle")
elif Input.is_action_pressed("ui_right"):
velocity.x = walk_speed
$AnimatedSprite.play("Right_Walk")
elif Input.is_action_just_released("ui_right"):
$AnimatedSprite.play("Right_Idle")
elif Input.is_action_pressed("ui_up"):
velocity.y = -walk_speed
$AnimatedSprite.play("Back_Walk")
elif Input.is_action_just_released("ui_up"):
$AnimatedSprite.play("Back_Idle")
elif Input.is_action_pressed("ui_down"):
velocity.y = walk_speed
$AnimatedSprite.play("Front_Walk")
elif Input.is_action_just_released("ui_down"):
$AnimatedSprite.play("Front_Idle")
The line where I have entered two inputs with “and” does not work, no difference in animation or speed, what am I doing wrong? Also all comments are welcomed about improving the code.
Essentially what I want is:
- a character that walks in 4 directions (done, sort of)
- stops and stays idle in the direction they walked
- runs in all those directions while shift is held
Thanks for the help!