Untitled
unknown
plain_text
10 months ago
1.1 kB
6
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