extends CharacterBody3D const SPEED = 150.0 const RUN_SPEED = 400.0 const JUMP_VELOCITY = 200 var last_direction:= Vector3.ONE @onready var camera: Camera3D = $Camera3D func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): velocity += get_gravity() * delta 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) 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) var t: Material = $MeshInstance3D.material_override t.uv1_scale = last_direction move_and_slide() # handle camera camera.position.x = lerp(camera.position.x, position.x, 0.08) camera.position.y = lerp(camera.position.y, position.y, 0.08) + 0.07 camera.position.z = position.z + 4 func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseButton: if event.is_pressed(): if event.button_index == MOUSE_BUTTON_WHEEL_UP: camera.fov -= 1 * (5 if Input.is_key_pressed(KEY_SHIFT) else 1) camera.size -= 1 * (0.2 if Input.is_key_pressed(KEY_SHIFT) else 0.05) if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: camera.fov += 1 * (5 if Input.is_key_pressed(KEY_SHIFT) else 1) camera.size += 1 * (0.2 if Input.is_key_pressed(KEY_SHIFT) else 0.05)