2024-12-28 01:58:19 +01:00

25 lines
675 B
GDScript

extends CharacterBody3D
const SPEED = 150.0
const JUMP_VELOCITY = 200
signal test
var last_direction:= Vector3.ONE
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
self.velocity.x = delta * SPEED * Input.get_axis("move_left", "move_right")
self.velocity.z = delta * SPEED * Input.get_axis("move_forward", "move_back")
if Input.is_key_pressed(KEY_SPACE) and is_on_floor():
self.velocity.y = delta * JUMP_VELOCITY
var i = int(Input.get_axis("move_left", "move_right"))
if i:
last_direction = Vector3(i, 1, 1)
$MeshInstance3D.set_scale(last_direction)
move_and_slide()