open-fpsz/characters/player/player.tscn
2024-04-09 21:36:43 +00:00

155 lines
5.3 KiB
Plaintext

[gd_scene load_steps=11 format=3 uid="uid://cbhx1xme0sb7k"]
[ext_resource type="Script" path="res://characters/player/player.gd" id="1_ymjub"]
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="2_5qvi2"]
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://weapons/space_gun/space_gun.tscn" id="2_ka38u"]
[ext_resource type="Shape3D" uid="uid://dkwljsgaflf31" path="res://characters/player/collision_shape.res" id="2_y6kgj"]
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://components/health_component.tscn" id="5_dlsxj"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
resource_local_to_scene = true
bounce = 1.0
absorbent = true
[sub_resource type="CapsuleMesh" id="CapsuleMesh_vmqfq"]
radius = 0.3
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rqdp6"]
properties/0/path = NodePath(".:linear_velocity")
properties/0/spawn = true
properties/0/replication_mode = 1
properties/1/path = NodePath(".:position")
properties/1/spawn = true
properties/1/replication_mode = 1
properties/2/path = NodePath(".:player_id")
properties/2/spawn = true
properties/2/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5j4ew"]
properties/0/path = NodePath(".:direction")
properties/0/spawn = false
properties/0/replication_mode = 1
properties/1/path = NodePath(".:jetting")
properties/1/spawn = false
properties/1/replication_mode = 2
properties/2/path = NodePath(".:camera_rotation")
properties/2/spawn = false
properties/2/replication_mode = 1
properties/3/path = NodePath(".:skiing")
properties/3/spawn = false
properties/3/replication_mode = 2
[sub_resource type="GDScript" id="GDScript_uy24w"]
script/source = "extends MultiplayerSynchronizer
class_name PlayerInput
@export var jumping = false
@export var jetting = false
@export var skiing = false
@export var direction = Vector2.ZERO
@export var camera_rotation : Vector2
@export var MOUSE_SENSITIVITY : float = 0.5
var _mouse_position: Vector2
func _ready():
enable()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _unhandled_input(event: InputEvent) -> void:
var mouse_mode = Input.get_mouse_mode()
# isolate mouse events
if event is InputEventMouseMotion:
if mouse_mode == Input.MOUSE_MODE_CAPTURED:
# retrieve mouse position relative to last frame
_mouse_position = event.relative * MOUSE_SENSITIVITY
func _process(delta):
direction = Input.get_vector(\"left\", \"right\", \"forward\", \"backward\")
if Input.is_action_just_pressed(\"jump_and_jet\"):
jump.rpc()
if Input.is_action_just_pressed(\"fire_primary\"):
fire_primary.rpc()
jetting = Input.is_action_pressed(\"jump_and_jet\")
skiing = Input.is_action_pressed(\"ski\")
_update_camera(delta)
@rpc(\"call_local\")
func jump():
jumping = true
@rpc(\"call_local\")
func fire_primary():
$\"../SpringArm3D/Inventory/SpaceGun\".fire_primary()
func _update_camera(delta):
# clamp vertical rotation (head motion)
camera_rotation.y -= _mouse_position.y * delta
camera_rotation.y = clamp(camera_rotation.y, deg_to_rad(-90.0),deg_to_rad(90.0))
# wrap horizontal rotation (to prevent accumulation)
camera_rotation.x -= _mouse_position.x * delta
camera_rotation.x = wrapf(camera_rotation.x, deg_to_rad(0.0),deg_to_rad(360.0))
# reset mouse motion until next input event
_mouse_position = Vector2.ZERO
func disable():
set_process(false)
set_process_unhandled_input(false)
func enable():
var has_authority = get_multiplayer_authority() == multiplayer.get_unique_id()
set_process(has_authority)
set_process_unhandled_input(has_authority)
"
[node name="Player" type="RigidBody3D"]
axis_lock_angular_x = true
axis_lock_angular_y = true
axis_lock_angular_z = true
mass = 75.0
physics_material_override = SubResource("PhysicsMaterial_clur0")
continuous_cd = true
script = ExtResource("1_ymjub")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("CapsuleMesh_vmqfq")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = ExtResource("2_y6kgj")
[node name="ShapeCast3D" type="ShapeCast3D" parent="."]
transform = Transform3D(1.05, 0, 0, 0, 1.05, 0, 0, 0, 1.05, 0, 0, 0)
shape = ExtResource("2_y6kgj")
target_position = Vector3(0, 0, 0)
collide_with_areas = true
[node name="HUD" parent="." instance=ExtResource("2_5qvi2")]
[node name="SpringArm3D" type="SpringArm3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
spring_length = 0.0
[node name="Camera3D" type="Camera3D" parent="SpringArm3D"]
fov = 100.0
near = 0.1
[node name="Inventory" type="Node3D" parent="SpringArm3D"]
[node name="SpaceGun" parent="SpringArm3D/Inventory" instance=ExtResource("2_ka38u")]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 0.281712, -0.095, -0.353461)
[node name="HealthComponent" parent="." instance=ExtResource("5_dlsxj")]
[node name="ServerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_rqdp6")
[node name="PlayerInput" type="MultiplayerSynchronizer" parent="."]
root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
script = SubResource("GDScript_uy24w")
[connection signal="health_changed" from="HealthComponent" to="HUD" method="_on_health_changed"]
[connection signal="health_zeroed" from="HealthComponent" to="." method="die"]