Just record me going through the house

This commit is contained in:
Vojta committed 2025-06-19 00:10:14 +02:00
1 parent 2de2b7f5ee
commit 700fed5a87
5 files changed
+58 -40

No files matched your search

+37 -23
View File
@@ -30,37 +30,51 @@ func _process(delta: float) -> void:
rotation.y = lerp_angle(rotation.y, target_rotation.y, delta * ROTATION_SPEED)
camera.rotation.x = lerp_angle(camera.rotation.x, target_rotation.x, delta * ROTATION_SPEED)
func _physics_process(delta: float) -> void:
var right: Vector3 = (global_transform.basis.x * Vector3(1, 0, 1)).normalized()
var forward: Vector3 = (-global_transform.basis.z * Vector3(1, 0, 1)).normalized()
var has_input = false
velocity.x = 0
velocity.z = 0
const ACCELERATION := 10.0
const DECELERATION := 6.0
var input_direction := Vector3.ZERO
var target_velocity := Vector3.ZERO
func _get_input_direction() -> Vector3:
var direction := Vector3.ZERO
if Input.is_key_pressed(KEY_LEFT) or Input.is_key_pressed(KEY_A):
has_input = true
velocity -= right
direction.x -= 1
if Input.is_key_pressed(KEY_RIGHT) or Input.is_key_pressed(KEY_D):
has_input = true
velocity += right
direction.x += 1
if Input.is_key_pressed(KEY_UP) or Input.is_key_pressed(KEY_W):
has_input = true
velocity += forward
direction.z += 1
if Input.is_key_pressed(KEY_DOWN) or Input.is_key_pressed(KEY_S):
has_input = true
velocity -= forward
direction.z -= 1
return direction.normalized()
func _physics_process(delta: float) -> void:
# Get input direction relative to player orientation
input_direction = _get_input_direction()
if has_input:
var normalized_horizontal_velocity = Vector2(velocity.x, velocity.z).normalized()
velocity.x = normalized_horizontal_velocity.x * SPEED
velocity.z = normalized_horizontal_velocity.y * SPEED
var basis := global_transform.basis
var forward := -basis.z.normalized()
var right := basis.x.normalized()
# Desired horizontal movement direction in world space
var desired_velocity : Vector3 = (right * input_direction.x + forward * input_direction.z) * SPEED
desired_velocity.y = 0 # Only horizontal
# Smooth acceleration/deceleration
var accel := DECELERATION if input_direction == Vector3.ZERO else ACCELERATION
target_velocity.x = lerp(target_velocity.x, desired_velocity.x, accel * delta)
target_velocity.z = lerp(target_velocity.z, desired_velocity.z, accel * delta)
# Preserve existing vertical velocity
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
target_velocity.y += get_gravity().y * delta
else:
target_velocity.y = 0
if Input.is_action_just_pressed("ui_accept"):
target_velocity.y = JUMP_VELOCITY
# Apply movement
velocity = target_velocity
move_and_slide()