49 lines
1.2 KiB
GDScript
49 lines
1.2 KiB
GDScript
extends CharacterBody3D
|
|
|
|
|
|
@export var SPEED: float = 10.0
|
|
@export var SENSI : float = 0.005
|
|
|
|
@export_group("Children")
|
|
@export var head: Node3D
|
|
|
|
|
|
var life: float = 100
|
|
var delay_shot:float = 0
|
|
var bullets:int = 11
|
|
var reloading:bool = false
|
|
var current_time_reloading: float = 0
|
|
var bump: Vector3 = Vector3.ZERO
|
|
var current_song = 0
|
|
|
|
func _ready() -> void:
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
add_to_group("player")
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event is InputEventMouseMotion:
|
|
head.rotate_x(-event.relative.y * SENSI)
|
|
rotate_y(-event.relative.x * SENSI)
|
|
head.rotation.x = clamp(head.rotation.x, -PI/2, PI/2)
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
# Add the gravity.
|
|
if not is_on_floor():
|
|
if velocity.y < 0:
|
|
velocity += get_gravity() * delta * 2
|
|
else:
|
|
velocity += get_gravity() * delta * 3
|
|
|
|
var input_dir := Input.get_vector("left", "right", "up", "down")
|
|
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
if direction:
|
|
velocity.x = direction.x * SPEED
|
|
velocity.z = direction.z * SPEED
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
velocity.z = move_toward(velocity.z, 0, SPEED)
|
|
|
|
move_and_slide()
|