Noobie Question (maybe). Im very new to godot, and game dev in general.
So, I have this problem. My GDSCRIPT if statment is supposed to be true but its not working. The animation won't play idle after the player has moved, or increased their velocity and back to no velocity. :
extends CharacterBody2D
@export var speed = 200
var mouse_position = null
var engine_on = true
var rotation_speed = PI # or 180 degrees
@onready var animated_sprite_2d = $AnimatedSprite2D
var animation_played = false
func _physics_process(delta):
Reset the player's velocity
velocity = Vector2(0, 0)
mouse_position = get_global_mouse_position()
var r = global_rotation
var angle = mouse_position.angle()
var angle_delta = rotation_speed * delta
angle = lerp_angle(r, angle, 0.1)
angle = clamp(angle, r - angle_delta, r + angle_delta)
if Input.is_action_pressed("forward") && engine_on:
$AnimatedSprite2D.play("flying-loop")
var direction = (mouse_position - position).normalized()
velocity = direction * speed
else:
Vector2(0, 0)
if velocity == Vector2(0, 0) && not animation_played:
$AnimatedSprite2D.play("flying_to_idle")
animation_played = true
print(engine_on)
print("Velocity:", velocity)
move_and_slide()
global_rotation = angle