30 lines
859 B
GDScript3
Raw Normal View History

2024-12-27 21:00:07 +01:00
extends CharacterBody3D
const SPEED = 150.0
2024-12-31 05:19:57 +01:00
const RUN_SPEED = 400.0
2024-12-27 21:00:07 +01:00
const JUMP_VELOCITY = 200
signal test
2024-12-28 01:58:19 +01:00
var last_direction:= Vector3.ONE
2024-12-27 21:00:07 +01:00
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
2024-12-31 05:19:57 +01:00
var k = RUN_SPEED if Input.is_key_pressed(KEY_SHIFT) else SPEED
self.velocity.x = delta * k * Input.get_axis("move_left", "move_right")
self.velocity.z = delta * k * Input.get_axis("move_forward", "move_back")
Messagebus.DEBUG_XYZ.emit(self.global_transform.origin)
2024-12-27 21:00:07 +01:00
if Input.is_key_pressed(KEY_SPACE) and is_on_floor():
self.velocity.y = delta * JUMP_VELOCITY
2024-12-28 01:58:19 +01:00
var i = int(Input.get_axis("move_left", "move_right"))
if i:
last_direction = Vector3(i, 1, 1)
2024-12-31 05:46:18 +01:00
var t: Material = $MeshInstance3D.material_override
t.uv1_scale = last_direction
2024-12-27 21:00:07 +01:00
move_and_slide()