#Godot 4 seems to ignore my exported variable for direction.

2 messages · Page 1 of 1 (latest)

low bluff
#

extends CharacterBody3D

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var direction = 0

func _ready():

if direction:
    $AnimatedSprite3d.play("walk")

if direction:
    velocity.x = -1
    $AnimatedSprite3d.flip_h = true
    
if direction:
    velocity.x = 1
    $AnimatedSprite3d.flip_h = true

func _physics_process(delta):

if is_on_wall():
    direction = direction * -1
    $AnimatedSprite3d.flip_h = not $AnimatedSprite3d.flip_h

# Add the gravity.
if not is_on_floor():
    velocity.y -= gravity * delta

move_and_slide()
#

if I set my direction to 1 or -1 the enemy still moves to the right