decouple camera from runner position
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
.godot/
|
.godot/
|
||||||
/android/
|
/android/
|
||||||
build/
|
build/
|
||||||
|
*.tmp
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
[gd_scene load_steps=16 format=3 uid="uid://8esyynmieyog"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/runner.gd" id="1_d63rt"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/runner_input.gd" id="2_xmliy"]
|
|
||||||
[ext_resource type="Material" uid="uid://ccrb46njti2ke" path="res://materials/runner.tres" id="3_6c0ro"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/state_machine.gd" id="4_40cmc"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/states/idle.gd" id="5_hq6tn"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/states/move.gd" id="6_1teax"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/states/fall.gd" id="7_jfat4"]
|
|
||||||
|
|
||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ukf45"]
|
|
||||||
properties/0/path = NodePath(".:player_id")
|
|
||||||
properties/0/spawn = true
|
|
||||||
properties/0/replication_mode = 2
|
|
||||||
properties/1/path = NodePath(".:server_position")
|
|
||||||
properties/1/spawn = true
|
|
||||||
properties/1/replication_mode = 2
|
|
||||||
properties/2/path = NodePath(".:server_rotation")
|
|
||||||
properties/2/spawn = true
|
|
||||||
properties/2/replication_mode = 2
|
|
||||||
|
|
||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_1agtp"]
|
|
||||||
properties/0/path = NodePath("RunnerInput:move_direction")
|
|
||||||
properties/0/spawn = true
|
|
||||||
properties/0/replication_mode = 2
|
|
||||||
|
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_wsx1k"]
|
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_j6tb3"]
|
|
||||||
radius = 0.3
|
|
||||||
height = 1.8
|
|
||||||
|
|
||||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_di3a0"]
|
|
||||||
radius = 0.3
|
|
||||||
height = 1.8
|
|
||||||
|
|
||||||
[sub_resource type="PrismMesh" id="PrismMesh_fcj1v"]
|
|
||||||
|
|
||||||
[sub_resource type="SphereMesh" id="SphereMesh_tudvv"]
|
|
||||||
|
|
||||||
[sub_resource type="SphereMesh" id="SphereMesh_1gltg"]
|
|
||||||
|
|
||||||
[node name="Runner" type="CharacterBody3D" node_paths=PackedStringArray("state_machine")]
|
|
||||||
script = ExtResource("1_d63rt")
|
|
||||||
state_machine = NodePath("StateMachine")
|
|
||||||
|
|
||||||
[node name="RunnerSync" type="MultiplayerSynchronizer" parent="."]
|
|
||||||
replication_config = SubResource("SceneReplicationConfig_ukf45")
|
|
||||||
|
|
||||||
[node name="RunnerInput" type="MultiplayerSynchronizer" parent="."]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
replication_config = SubResource("SceneReplicationConfig_1agtp")
|
|
||||||
script = ExtResource("2_xmliy")
|
|
||||||
|
|
||||||
[node name="Camera" type="Camera3D" parent="."]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
|
|
||||||
[node name="CameraPivot" type="Node3D" parent="."]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
|
||||||
|
|
||||||
[node name="CameraSpringArm" type="SpringArm3D" parent="CameraPivot"]
|
|
||||||
shape = SubResource("SphereShape3D_wsx1k")
|
|
||||||
spring_length = 3.5
|
|
||||||
|
|
||||||
[node name="CameraTarget" type="Node3D" parent="CameraPivot/CameraSpringArm"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
|
||||||
|
|
||||||
[node name="Collider" type="CollisionShape3D" parent="."]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
|
||||||
shape = SubResource("CapsuleShape3D_j6tb3")
|
|
||||||
|
|
||||||
[node name="Skin" type="Node3D" parent="."]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
|
|
||||||
[node name="MainBody" type="MeshInstance3D" parent="Skin"]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
|
||||||
mesh = SubResource("CapsuleMesh_di3a0")
|
|
||||||
skeleton = NodePath("../..")
|
|
||||||
surface_material_override/0 = ExtResource("3_6c0ro")
|
|
||||||
|
|
||||||
[node name="Beak" type="MeshInstance3D" parent="Skin/MainBody"]
|
|
||||||
transform = Transform3D(0.35, 0, 0, 0, -1.09278e-08, 0.1, 0, -0.25, -4.37114e-09, 0, 0.65, -0.3)
|
|
||||||
visible = false
|
|
||||||
mesh = SubResource("PrismMesh_fcj1v")
|
|
||||||
surface_material_override/0 = ExtResource("3_6c0ro")
|
|
||||||
|
|
||||||
[node name="RightEye" type="MeshInstance3D" parent="Skin/MainBody"]
|
|
||||||
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0.1, 0.6, -0.25)
|
|
||||||
mesh = SubResource("SphereMesh_tudvv")
|
|
||||||
|
|
||||||
[node name="LeftEye" type="MeshInstance3D" parent="Skin/MainBody"]
|
|
||||||
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, -0.1, 0.6, -0.25)
|
|
||||||
mesh = SubResource("SphereMesh_1gltg")
|
|
||||||
|
|
||||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")]
|
|
||||||
script = ExtResource("4_40cmc")
|
|
||||||
current_state = NodePath("Idle")
|
|
||||||
|
|
||||||
[node name="Idle" type="Node" parent="StateMachine" node_paths=PackedStringArray("move_state")]
|
|
||||||
script = ExtResource("5_hq6tn")
|
|
||||||
move_state = NodePath("../Move")
|
|
||||||
|
|
||||||
[node name="Move" type="Node" parent="StateMachine" node_paths=PackedStringArray("idle_state", "fall_state")]
|
|
||||||
script = ExtResource("6_1teax")
|
|
||||||
idle_state = NodePath("../Idle")
|
|
||||||
fall_state = NodePath("../Fall")
|
|
||||||
|
|
||||||
[node name="Fall" type="Node" parent="StateMachine" node_paths=PackedStringArray("move_state", "idle_state")]
|
|
||||||
script = ExtResource("7_jfat4")
|
|
||||||
move_state = NodePath("../Move")
|
|
||||||
idle_state = NodePath("../Idle")
|
|
||||||
+14
-13
@@ -28,8 +28,6 @@ properties/1/path = NodePath("Input:walking")
|
|||||||
properties/1/spawn = true
|
properties/1/spawn = true
|
||||||
properties/1/replication_mode = 2
|
properties/1/replication_mode = 2
|
||||||
|
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_wsx1k"]
|
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_j6tb3"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_j6tb3"]
|
||||||
radius = 0.3
|
radius = 0.3
|
||||||
height = 1.8
|
height = 1.8
|
||||||
@@ -44,6 +42,8 @@ height = 1.8
|
|||||||
|
|
||||||
[sub_resource type="SphereMesh" id="SphereMesh_1gltg"]
|
[sub_resource type="SphereMesh" id="SphereMesh_1gltg"]
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_wsx1k"]
|
||||||
|
|
||||||
[node name="Runner" type="CharacterBody3D" node_paths=PackedStringArray("state_machine")]
|
[node name="Runner" type="CharacterBody3D" node_paths=PackedStringArray("state_machine")]
|
||||||
script = ExtResource("1_d63rt")
|
script = ExtResource("1_d63rt")
|
||||||
state_machine = NodePath("StateMachine")
|
state_machine = NodePath("StateMachine")
|
||||||
@@ -56,21 +56,10 @@ unique_name_in_owner = true
|
|||||||
replication_config = SubResource("SceneReplicationConfig_1agtp")
|
replication_config = SubResource("SceneReplicationConfig_1agtp")
|
||||||
script = ExtResource("2_xmliy")
|
script = ExtResource("2_xmliy")
|
||||||
|
|
||||||
[node name="Camera" type="Camera3D" parent="."]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
|
|
||||||
[node name="CameraPivot" type="Node3D" parent="."]
|
[node name="CameraPivot" type="Node3D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
||||||
|
|
||||||
[node name="CameraSpringArm" type="SpringArm3D" parent="CameraPivot"]
|
|
||||||
shape = SubResource("SphereShape3D_wsx1k")
|
|
||||||
spring_length = 3.5
|
|
||||||
|
|
||||||
[node name="CameraTarget" type="Node3D" parent="CameraPivot/CameraSpringArm"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
|
||||||
|
|
||||||
[node name="Collider" type="CollisionShape3D" parent="."]
|
[node name="Collider" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
shape = SubResource("CapsuleShape3D_j6tb3")
|
shape = SubResource("CapsuleShape3D_j6tb3")
|
||||||
@@ -96,6 +85,18 @@ mesh = SubResource("SphereMesh_tudvv")
|
|||||||
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, -0.1, 0.6, -0.25)
|
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, -0.1, 0.6, -0.25)
|
||||||
mesh = SubResource("SphereMesh_1gltg")
|
mesh = SubResource("SphereMesh_1gltg")
|
||||||
|
|
||||||
|
[node name="FloatingCamera" type="Node" parent="."]
|
||||||
|
|
||||||
|
[node name="CameraPlatform" type="Node3D" parent="FloatingCamera"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="CameraSpringArm" type="SpringArm3D" parent="FloatingCamera/CameraPlatform"]
|
||||||
|
shape = SubResource("SphereShape3D_wsx1k")
|
||||||
|
spring_length = 3.5
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera3D" parent="FloatingCamera/CameraPlatform/CameraSpringArm"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")]
|
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")]
|
||||||
script = ExtResource("4_40cmc")
|
script = ExtResource("4_40cmc")
|
||||||
current_state = NodePath("Idle")
|
current_state = NodePath("Idle")
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ extends MultiplayerSynchronizer
|
|||||||
@export var direction: Vector2 = Vector2.ZERO
|
@export var direction: Vector2 = Vector2.ZERO
|
||||||
@export var walking: bool = false
|
@export var walking: bool = false
|
||||||
|
|
||||||
|
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if multiplayer.is_server() or get_multiplayer_authority() != multiplayer.get_unique_id():
|
if multiplayer.is_server() or get_multiplayer_authority() != multiplayer.get_unique_id():
|
||||||
set_process(false)
|
set_process(false)
|
||||||
@@ -11,6 +13,6 @@ func _ready() -> void:
|
|||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
var directional_input := Input.get_vector("move_right", "move_left", "move_forward", "move_back")
|
var directional_input := Input.get_vector("move_right", "move_left", "move_forward", "move_back")
|
||||||
var camera_adjusted: Vector3 = (directional_input.x * %CameraTarget.global_basis.z) + (directional_input.y * %CameraTarget.global_basis.x)
|
var camera_adjusted: Vector3 = (directional_input.x * _camera_pivot.global_basis.z) + (directional_input.y * _camera_pivot.global_basis.x)
|
||||||
direction = Vector2(camera_adjusted.x, camera_adjusted.z).rotated(PI / 2.0).normalized()
|
direction = Vector2(camera_adjusted.x, camera_adjusted.z).rotated(PI / 2.0).normalized()
|
||||||
walking = Input.is_action_pressed("walk")
|
walking = Input.is_action_pressed("walk")
|
||||||
|
|||||||
+13
-12
@@ -9,7 +9,7 @@ extends CharacterBody3D
|
|||||||
|
|
||||||
@export_group("Camera")
|
@export_group("Camera")
|
||||||
@export_range(0.0, 1.0) var mouse_sensitivity := 0.2
|
@export_range(0.0, 1.0) var mouse_sensitivity := 0.2
|
||||||
@export var camera_follow_speed := 10.0
|
@export var camera_follow_speed := 20.0
|
||||||
@export var smooth_camera := false
|
@export var smooth_camera := false
|
||||||
|
|
||||||
@export_group("Movement")
|
@export_group("Movement")
|
||||||
@@ -21,11 +21,11 @@ extends CharacterBody3D
|
|||||||
|
|
||||||
@export_group("Client Tweening")
|
@export_group("Client Tweening")
|
||||||
@export var client_smoothing := false
|
@export var client_smoothing := false
|
||||||
@export var client_smoothing_speed := 5.0
|
@export var client_smoothing_speed := 10.0
|
||||||
@export var client_smoothing_rotation_speed := 10.0
|
@export var client_smoothing_rotation_speed := 25.0
|
||||||
|
|
||||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||||
@onready var _camera_target: Node3D = %CameraTarget
|
@onready var _camera_platform: Node3D = %CameraPlatform
|
||||||
@onready var _camera: Node3D = %Camera
|
@onready var _camera: Node3D = %Camera
|
||||||
@onready var skin: Node3D = %Skin
|
@onready var skin: Node3D = %Skin
|
||||||
|
|
||||||
@@ -59,6 +59,15 @@ func _input(event: InputEvent) -> void:
|
|||||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||||
camera_input_direction += event.screen_relative * mouse_sensitivity
|
camera_input_direction += event.screen_relative * mouse_sensitivity
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if multiplayer.get_unique_id() == player_id:
|
||||||
|
_camera_platform.global_rotation = _camera_pivot.global_rotation
|
||||||
|
|
||||||
|
if smooth_camera:
|
||||||
|
_camera_platform.global_position = lerp(_camera_platform.global_position, _camera_pivot.global_position, camera_follow_speed * delta)
|
||||||
|
else:
|
||||||
|
_camera_platform.global_position = _camera_pivot.global_position
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
state_machine.process_physics(delta)
|
state_machine.process_physics(delta)
|
||||||
if multiplayer.get_unique_id() == player_id:
|
if multiplayer.get_unique_id() == player_id:
|
||||||
@@ -67,15 +76,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
-PI / 3.0,
|
-PI / 3.0,
|
||||||
PI / 6.0,
|
PI / 6.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
_camera_pivot.rotation.y -= camera_input_direction.x * delta
|
_camera_pivot.rotation.y -= camera_input_direction.x * delta
|
||||||
_camera.global_rotation = _camera_pivot.global_rotation
|
|
||||||
|
|
||||||
if smooth_camera:
|
|
||||||
_camera.global_position = lerp(_camera.global_position, _camera_target.global_position, camera_follow_speed * delta)
|
|
||||||
else:
|
|
||||||
_camera.global_position = _camera_target.global_position
|
|
||||||
|
|
||||||
camera_input_direction = Vector2.ZERO
|
camera_input_direction = Vector2.ZERO
|
||||||
|
|
||||||
if not multiplayer.is_server():
|
if not multiplayer.is_server():
|
||||||
|
|||||||
Reference in New Issue
Block a user