WIP: Some updates
This commit is contained in:
@ -1,28 +1,35 @@
|
||||
extends Node3D
|
||||
extends CharacterBody3D
|
||||
class_name CharacterWrapper
|
||||
|
||||
@export var die_script: GDScript = null
|
||||
@export var owner_placeholder: Node3D = null
|
||||
@export var owner_placeholder: CharacterBody3D = null
|
||||
|
||||
@export var interpolation_speed: float = 10.0 # How quickly the model corrects position
|
||||
@export var velocity_influence: float = 1.0 # How much velocity is used for smoothing
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# Characters should be always controlled by the server and synced accross client
|
||||
# The owner should be responsible for the syncronization, since this node is
|
||||
# just a dummy that is following the controller
|
||||
#set_multiplayer_authority(1)
|
||||
|
||||
|
||||
pass # Replace with function body.
|
||||
func _physics_process(delta: float) -> void:
|
||||
set_multiplayer_authority(multiplayer.get_unique_id())
|
||||
if owner_placeholder:
|
||||
#global_transform.origin = owner_placeholder.global_transform.origin
|
||||
global_transform.origin = global_transform.origin.lerp(owner_placeholder.global_position, delta * 10)
|
||||
global_rotation = owner_placeholder.global_rotation
|
||||
global_position = owner_placeholder.global_position
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
#if not is_on_floor():
|
||||
#velocity += get_gravity() * delta
|
||||
#global_position = owner_placeholder.global_position
|
||||
|
||||
var server_pos = owner_placeholder.global_transform.origin
|
||||
var server_velocity = (server_pos - owner_placeholder.global_transform.origin) / delta
|
||||
|
||||
velocity = owner_placeholder.velocity
|
||||
global_transform.origin = global_transform.origin.lerp(server_pos, interpolation_speed * delta)
|
||||
global_transform.origin += velocity * velocity_influence * delta
|
||||
velocity = velocity.lerp(server_velocity, delta * interpolation_speed)
|
||||
move_and_slide()
|
||||
|
||||
# Set the owner placeholder, so the characters can send the requests to a node
|
||||
# it depends on
|
||||
func set_owner_placeholder(owner: Node3D):
|
||||
owner_placeholder = owner
|
||||
func set_owner_placeholder(owner_placeholder: Node3D):
|
||||
owner_placeholder = owner_placeholder
|
||||
|
||||
func die():
|
||||
push_warning("TODO: Implement ragdoll kind of dying and respawn character as an object")
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=20 format=4 uid="uid://ddwrs0so7swxn"]
|
||||
[gd_scene load_steps=21 format=4 uid="uid://ddwrs0so7swxn"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/characters/character_wrapper.gd" id="1_k4p2i"]
|
||||
[ext_resource type="Script" path="res://scenes/characters/hit_detected.gd" id="2_oqdj0"]
|
||||
@ -2322,7 +2322,11 @@ _data = {
|
||||
"t_pose": SubResource("Animation_jk3i7")
|
||||
}
|
||||
|
||||
[node name="Character" type="Node3D"]
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_gp5it"]
|
||||
|
||||
[node name="Character" type="CharacterBody3D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
script = ExtResource("1_k4p2i")
|
||||
|
||||
[node name="Model" type="Node3D" parent="."]
|
||||
@ -3015,6 +3019,9 @@ libraries = {
|
||||
"": SubResource("AnimationLibrary_1yo1h")
|
||||
}
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_gp5it")
|
||||
|
||||
[connection signal="body_part_hit" from="Model/Body/Skeleton3D/HeadAttachment/Area" to="." method="_on_area_body_part_hit"]
|
||||
[connection signal="body_part_hit" from="Model/Body/Skeleton3D/TorsoAttachment/Area" to="." method="_on_area_body_part_hit"]
|
||||
[connection signal="body_part_hit" from="Model/Body/Skeleton3D/RightHipAttachment/Area" to="." method="_on_area_body_part_hit"]
|
||||
|
Reference in New Issue
Block a user