projektluzid/player.gd
kevadesu fe1eb58626 wah
2025-05-29 01:45:43 +02:00

128 lines
4.5 KiB
GDScript

extends RigidBody3D
# Configure options
var mouse_sensitivity := 0.001
#@onready var levelcore = get_node("/root/Level_Core/LevelCore")
# Do not touch this part of the code
var twist_input := 0.0
var pitch_input := 0.0
# var levelcore: Node
@onready var audioplayer = get_node("SFX")
@onready var musicplayer = get_node("Music")
@onready var newmusicplayer = $MusicProper
@onready var twist_pivot := $TwistPivot
@onready var pitch_pivot := $TwistPivot/PitchPivot
@onready var currentscene = get_tree().current_scene
#@onready var levelcore = currentscene.get_path()
@onready var levelcore = get_node("/root/LevelCore")
#@onready var startmenu = get_node("/root/start/inGameUI")
var checkpoint: Vector3
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
checkpoint = levelcore.checkpoint0
# checkpoint = levelcore.checkpoint0
# while not get_node_or_null("/Level_Core/LevelCore"):
# await get_tree().process_frame # Yield until the next frame
# levelcore = get_node("/Level_Core/LevelCore")
# checkpoint = levelcore.checkpoint
# var player = get_node("/player/Player")
# If touches object
var touched = false
var health = 100
func teleport_to_checkpoint():
# levelcore = get_node("/root/LevelCore")
var target_position = checkpoint
global_transform.origin = target_position
print("teleport to ", target_position, " successful")
func _integrate_forces(state):
# while not get_node_or_null("/Level_Core/LevelCore"):
# await get_tree().process_frame
# print("levelcore set!")
for i in range(state.get_contact_count()):
var collider = state.get_contact_collider_object(i)
if collider is StaticBody3D and collider.name == "StaticBody3D_S1":
#checkpoint = levelcore.checkpoint1
print("chat we hit the checkpoint one")
# levelcore = get_node("/root/LevelCore")
if not checkpoint == levelcore.checkpoint1:
audioplayer.stream = load("res://assets/audio/SceneSpawn.wav")
audioplayer.play()
checkpoint = levelcore.checkpoint1
levelcore.checkpointtext.text = "station 1"
elif collider is StaticBody3D and collider.name == "StaticBody3D_S2":
print("chat we hit the checkpoint two")
if not checkpoint == levelcore.checkpoint2:
audioplayer.stream = load("res://assets/audio/SceneSpawn.wav")
audioplayer.play()
checkpoint = levelcore.checkpoint2
levelcore.checkpointtext.text = "station 2"
elif collider is StaticBody3D and collider.name == "StaticBody3D_S3":
if not checkpoint == levelcore.checkpoint3:
audioplayer.stream = load("res://assets/audio/SceneSpawn.wav")
audioplayer.play()
checkpoint = levelcore.checkpoint3
levelcore.checkpointtext.text = "station 3"
elif collider is StaticBody3D and collider.name == "StaticBody3D_T":
print("chat we hit the end")
if not checkpoint == levelcore.terminus:
audioplayer.stream = load("res://assets/audio/WinTada.wav")
audioplayer.play()
checkpoint = levelcore.terminus
levelcore.checkpointtext.text = "terminus"
#func _integrate_forces(state):
# for i in range(state.get_contact_count()):
# var collider = state.get_contact_collider_object(i)
# print("Collided with: ", collider)
# print("Name: ", collider.name)
# if collider is StaticBody3D and collider.name == "StaticBody3D_S1":
# touched = true
# print(">>> MATCH! <<<")
#func _integrate_forces(state):
# for i in range(state.get_contact_count()):
# var collider = state.get_contact_collider_object(i)
# print("Collision with: ", collider)
# if collider:
# print("Name: ", collider.name)
func _process(delta: float) -> void:
var input := Vector3.ZERO
input.x = Input.get_axis("move_left", "move_right")
input.z = Input.get_axis("move_forward", "move_back")
apply_central_force(twist_pivot.basis * input * 3000.0 * delta)
# apply_central_force(twist_pivot.basis * input * 6000.0 * delta)
# apply_central_force(twist_pivot.basis * input * 4500.0 * delta)
if Input.is_action_just_pressed("proluz_ui_pause"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed("proluz_ui_grab"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
twist_pivot.rotate_y(twist_input)
pitch_pivot.rotate_x(pitch_input)
pitch_pivot.rotation.x = clamp(pitch_pivot.rotation.x, deg_to_rad(-50), deg_to_rad(50))
twist_input = 0.0
pitch_input = 0.0
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
twist_input = - event.relative.x * mouse_sensitivity
pitch_input = - event.relative.y * mouse_sensitivity