Files
demo-godot/palyer.gd

30 lines
757 B
GDScript3
Raw Normal View History

2026-01-04 19:35:08 +08:00
extends CharacterBody3D
var speed = 14
var fall_acceleration = 75
var target_velocity = Vector3.ZERO
func _physics_process(delta: float):
var direction = Vector3.ZERO
if Input.is_action_pressed("move_forward"):
direction.z -= 1
if Input.is_action_pressed("move_back"):
direction.z += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_right"):
direction.x += 1
if direction != Vector3.ZERO:
direction = direction.normalized()
$pivot.basis = Basis.looking_at(direction)
target_velocity.x = direction.x * speed
target_velocity.z = direction.z * speed
if !is_on_floor():
target_velocity.y = target_velocity.y - ( fall_acceleration * delta )
velocity = target_velocity
move_and_slide()