49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| class_name Player
 | |
| extends CharacterBody3D
 | |
| 
 | |
| @export var _respawn_height: float = -5
 | |
| @export var _collision_debug_material: Material
 | |
| 
 | |
| var movement: PlayerMovement = PlayerMovement.new()
 | |
| var aiming: PlayerAiming = PlayerAiming.new()
 | |
| 
 | |
| var _respawn_point: Vector3
 | |
| var _debug_collision_shapes := DebugCollisionShapes.new()
 | |
| 
 | |
| 
 | |
| func _ready() -> void:
 | |
| 	_respawn_point = global_position
 | |
| 	Referencer.player = self
 | |
| 	_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
 | |
| 
 | |
| 
 | |
| func _process(_delta: float) -> void:
 | |
| 	aiming.controller_aiming(movement.move_input)
 | |
| 	call_deferred("_mouse_aiming")
 | |
| 	_process_respawning()
 | |
| 
 | |
| 	Debugger.marker("aim", global_position + aiming.aim_offset)
 | |
| 
 | |
| 
 | |
| func _physics_process(delta: float) -> void:
 | |
| 	if not is_multiplayer_authority():
 | |
| 		return
 | |
| 
 | |
| 	velocity = movement.lateral_movement(velocity, delta)
 | |
| 	velocity = movement.vertical_movement(velocity, delta, is_on_floor())
 | |
| 
 | |
| 	move_and_slide()
 | |
| 
 | |
| 
 | |
| func _mouse_aiming() -> void:
 | |
| 	var mouse_pos := get_viewport().get_mouse_position()
 | |
| 	aiming.mouse_aiming(mouse_pos, global_position, is_on_floor())
 | |
| 	if aiming.aim_offset.length() > 0:
 | |
| 		look_at(global_position + aiming.aim_offset, Vector3.UP, true)
 | |
| 
 | |
| 
 | |
| func _process_respawning() -> void:
 | |
| 	if global_position.y < _respawn_height:
 | |
| 		global_position = _respawn_point
 | |
| 		velocity = Vector3.ZERO
 |