Trying 3D (tutorial)

This commit is contained in:
2025-11-15 22:17:29 +01:00
parent c57f07ffc2
commit 9628fff680
24 changed files with 435 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
extends CharacterBody3D
@export var speed = 14
@export var fall_acc = 75
@export var jump_impulse = 40
var target_vel = Vector3.ZERO
func _physics_process(delta: float) -> void:
# Move
var dir = Vector3.ZERO
if Input.is_action_pressed("move_left"):
dir.x -= 1
if Input.is_action_pressed("move_right"):
dir.x += 1
if Input.is_action_pressed("move_forward"):
dir.z -= 1
if Input.is_action_pressed("move_back"):
dir.z += 1
if dir != Vector3.ZERO:
dir = dir.normalized()
$Pivot.basis = Basis.looking_at(dir)
# Ground vel. (overwrite y later)
target_vel = dir * speed
# vert. vel.
target_vel.y = 0
if not is_on_floor():
target_vel.y -= fall_acc * delta
# Jump
if is_on_floor() and Input.is_action_just_pressed("jump"):
target_vel.y = jump_impulse
velocity = target_vel
move_and_slide()