I'm learning about platformers, and I have a VisibilityEnabler2D as a child of the root node with physics process parent activated. This means that when The enemy enters and leaves the camera range, it won't move. However at the start of the game, the enemies move because they haven't been viewed yet. I used a tutorial to try to fix it by initially disabling my movement in a _ready function, but that only does something with Physics process parent turned off (disables the movement entirely). My code exactly matches the tutorial. Any clues where I went wrong?
extends KinematicBody2D
class_name Actor
export var speed: = Vector2(50, 600)
var velocity: Vector2 = Vector2()
export var gravity: = 800
func _ready() -> void:
set_physics_process(false)
velocity.x = -speed.x
func _physics_process(delta: float) -> void:
velocity.y += gravity * delta
if is_on_wall() or not $RayCast2D1.is_colliding() or not $RayCast2D2.is_colliding():
velocity.x *= -1
velocity.y = move_and_slide(velocity, Vector2.UP).y