add player respawning
This commit is contained in:
parent
92678240ab
commit
0686915bfe
@ -14,12 +14,6 @@
|
||||
[node name="Debugger" parent="." instance=ExtResource("6_lpvoh")]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_f4ehn")]
|
||||
_input_mode = 1
|
||||
_device_index = 1
|
||||
|
||||
[node name="Player2" parent="." instance=ExtResource("2_f4ehn")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.09589, 0, 1.53304)
|
||||
_input_mode = 1
|
||||
|
||||
[node name="Geometry" type="Node" parent="."]
|
||||
|
||||
|
||||
@ -6,15 +6,20 @@ static var instances: Array[Player]
|
||||
@export var _input_mode: Inputer.Mode = Inputer.Mode.KB_MOUSE
|
||||
@export var _device_index: int = 0
|
||||
|
||||
@export var _respawn_height: float = -5
|
||||
|
||||
@export_group("References")
|
||||
@export var _mover: PlayerMover
|
||||
|
||||
var _respawn_point: Vector3
|
||||
|
||||
|
||||
static func is_single_player() -> bool:
|
||||
return instances.size() <= 1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_respawn_point = global_position
|
||||
instances.append(self)
|
||||
|
||||
|
||||
@ -22,6 +27,10 @@ func _exit_tree() -> void:
|
||||
instances.erase(self)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
_process_respawning()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
velocity = _mover.handle_movement(velocity, delta, is_on_floor(), true)
|
||||
move_and_slide()
|
||||
@ -44,3 +53,10 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
|
||||
func input_mode_is(mode: Inputer.Mode) -> bool:
|
||||
return is_single_player() or _input_mode == mode
|
||||
|
||||
|
||||
func _process_respawning() -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
velocity = Vector3.ZERO
|
||||
reset_physics_interpolation()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user