35 lines
1.1 KiB
GDScript
35 lines
1.1 KiB
GDScript
extends CharacterBody3D
|
|
|
|
const SPEED = 5.0
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
@export var turn_speed: float = 10.0
|
|
|
|
@onready var camera_pivot: Node3D = $SpringArmPivot
|
|
@onready var cube_guy: Node3D = $bull_v10
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if not is_on_floor():
|
|
velocity += get_gravity() * delta
|
|
|
|
if Input.is_action_just_pressed("jump") and is_on_floor():
|
|
velocity.y = JUMP_VELOCITY
|
|
|
|
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
|
var cam_basis := camera_pivot.global_transform.basis
|
|
var flat_forward := -Vector3(cam_basis.z.x, 0.0, cam_basis.z.z).normalized()
|
|
var flat_right := Vector3(cam_basis.x.x, 0.0, cam_basis.x.z).normalized()
|
|
var direction := (flat_forward * -input_dir.y + flat_right * input_dir.x).normalized()
|
|
|
|
if direction:
|
|
velocity.x = direction.x * SPEED
|
|
velocity.z = direction.z * SPEED
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0.0, SPEED)
|
|
velocity.z = move_toward(velocity.z, 0.0, SPEED)
|
|
|
|
cube_guy.rotation.y = lerp_angle(cube_guy.rotation.y, camera_pivot.rotation.y + PI, delta * turn_speed)
|
|
|
|
move_and_slide()
|