Add a world model and refactor the controller
This commit is contained in:
@ -14,6 +14,7 @@ class_name Player extends CharacterBody3D
|
||||
@onready var upper_torso_default_position: Vector3 = upper_torso.position
|
||||
@export var ANIMATION_PLAYER : AnimationPlayer
|
||||
@onready var body: Node3D = $RealBody
|
||||
|
||||
var jumping: bool = false
|
||||
var mouse_captured: bool = false
|
||||
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
@ -32,6 +33,10 @@ var is_crouch: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
$"../MultiplayerSynchronizer".set_multiplayer_authority(str($"..".name).to_int())
|
||||
# If player is not the current player, we need to add a model
|
||||
if str($"..".name).to_int() != multiplayer.get_unique_id():
|
||||
var dummy = ResourceLoader.load("res://scenes/characters/blue/dummy.tscn").instantiate()
|
||||
add_child(dummy)
|
||||
enable_camera()
|
||||
capture_mouse()
|
||||
#print("I am " + str(multiplayer.get_unique_id()) + "I'm controling " + str($"../MultiplayerSynchronizer".get_multiplayer_authority()))
|
||||
@ -42,7 +47,8 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if mouse_captured: _rotate_camera()
|
||||
if Input.is_action_just_pressed("jump"): jumping = true
|
||||
if Input.is_action_just_pressed("exit"): get_tree().quit()
|
||||
if Input.is_action_just_pressed("shot"): $UpperTorso/ViewModelCamera.shot()
|
||||
if str($"..".name).to_int() == multiplayer.get_unique_id():
|
||||
if Input.is_action_just_pressed("shot"): $UpperTorso/ViewModelCamera.shot()
|
||||
if Input.is_action_just_pressed("reload"): $Body/UpperTorso/CameraMount/Camera.reload()
|
||||
if Input.is_action_just_pressed("crouch"): crouch()
|
||||
if Input.is_action_just_released("crouch"): uncrouch()
|
||||
@ -66,8 +72,9 @@ func release_mouse() -> void:
|
||||
mouse_captured = false
|
||||
|
||||
func _rotate_camera(sens_mod: float = 1.0) -> void:
|
||||
character.rotation.y -= look_dir.x * camera_sens * sens_mod
|
||||
camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
|
||||
if str($"..".name).to_int() == multiplayer.get_unique_id():
|
||||
character.rotation.y -= look_dir.x * camera_sens * sens_mod
|
||||
camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
|
||||
|
||||
func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void:
|
||||
var joypad_dir: Vector2 = Input.get_vector("look_left","look_right","look_up","look_down")
|
||||
@ -84,7 +91,7 @@ func _walk(delta: float) -> Vector3:
|
||||
var cur_speed: float
|
||||
if is_crouch:
|
||||
cur_speed = speed / 3
|
||||
#upper_torso.position.y -= 10
|
||||
#upper_torso.position.y -= 10
|
||||
else:
|
||||
cur_speed = speed
|
||||
if Input.is_action_pressed("silent_walk"):
|
||||
|
Reference in New Issue
Block a user