Godot Version
4.3
Question
`I want to give my player some walking animations that end when the player stops moving, but when I put an if statement inside the func _process(delta stuff), it gives me an Assignment is not allowed inside an expression error. Here’s the code for context:
@onready var Cuc_Sprite: Sprite2D = $Sprite2D
@onready var cuc_anims: AnimationPlayer = $Sprite2D/Cuc_Anims
var Speed = 250.0 #Speed
const Accelerant = 5.0 #Acceleration
var input: Vector2
func get_input():
input.x = Input.get_action_strength("Right") - Input.get_action_strength("Left") #Detects Left and Right inputs
input.y = Input.get_action_strength("Down") - Input.get_action_strength("Up") #Detects Down and Up inputs
return input.normalized() #Makes so you don't go Sonic speed if you press both X and Y inputs
func _process(delta: float) -> void:
var PlayerInput = get_input()
velocity = lerp(velocity, PlayerInput * Speed, delta * Accelerant) #Makes you walk and it's smooth (Accelerant value is for the smoothing lol)
move_and_slide() #Makes you shmove
#I put the if statement here
if Input.is_action_pressed("Left"):
Cuc_Sprite.flip_h = true
elif Input.is_action_pressed("Right"):
Cuc_Sprite.flip_h = false
else:
pass```