Untitled

 avatar
unknown
plain_text
14 days ago
1.1 kB
3
Indexable
extends CharacterBody3D

@export var speed = 20.0
@export var acceleration = 5.0
@export var turn_speed = 2.0

var velocity = Vector3.ZERO

func _physics_process(delta):
    var direction = Vector3.ZERO

        if Input.is_action_pressed("move_forward"):
                direction -= transform.basis.z  # Move forward
                    if Input.is_action_pressed("move_backward"):
                            direction += transform.basis.z  # Move backward

                                if Input.is_action_pressed("turn_left"):
                                        rotation.y += turn_speed * delta  # Turn left
                                            if Input.is_action_pressed("turn_right"):
                                                    rotation.y -= turn_speed * delta  # Turn right

                                                        # Smooth acceleration
                                                            velocity = velocity.lerp(direction * speed, acceleration * delta)
                                                                move_and_slide(velocity)
Editor is loading...
Leave a Comment