52 lines
1.7 KiB
GDScript3
52 lines
1.7 KiB
GDScript3
![]() |
extends Node3D
|
||
|
class_name ServerNode
|
||
|
|
||
|
var jumping := false
|
||
|
var input_direction: Vector2
|
||
|
@export var owner_id: int = 0
|
||
|
|
||
|
@onready var camera_mount: Node3D = $SharedNode/CameraMount
|
||
|
@onready var shared_node: CharacterBody3D = $SharedNode
|
||
|
|
||
|
func _ready() -> void:
|
||
|
shared_node.set_collision_layer_value(3, true)
|
||
|
shared_node.set_collision_mask_value(1, true)
|
||
|
shared_node.set_collision_mask_value(3, true)
|
||
|
# Deploy a local controller node
|
||
|
func _physics_process(delta: float) -> void:
|
||
|
if not shared_node.is_on_floor():
|
||
|
shared_node.velocity += shared_node.get_gravity() * delta
|
||
|
if shared_node.is_on_floor() && jumping:
|
||
|
shared_node.velocity.y = consts.DEFAULT_JUMP_VELOCITY
|
||
|
|
||
|
|
||
|
#if shooting:
|
||
|
jumping = false
|
||
|
|
||
|
var direction := (shared_node.transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||
|
if shared_node.is_on_floor():
|
||
|
if direction:
|
||
|
#first_view_legs_anim.play("Run Forward")
|
||
|
shared_node.velocity.x = direction.x * consts.DEFAULT_CHARACTER_SPEED
|
||
|
shared_node.velocity.z = direction.z * consts.DEFAULT_CHARACTER_SPEED
|
||
|
else:
|
||
|
shared_node.velocity.x = move_toward(shared_node.velocity.x, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||
|
shared_node.velocity.z = move_toward(shared_node.velocity.z, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||
|
shared_node.move_and_slide()
|
||
|
|
||
|
@rpc("any_peer", "call_local", "unreliable")
|
||
|
func jump():
|
||
|
jumping = true
|
||
|
|
||
|
@rpc("any_peer", "call_local", "unreliable")
|
||
|
func set_input_direction(new_input_direction: Vector2):
|
||
|
input_direction = new_input_direction
|
||
|
|
||
|
@rpc("any_peer", "call_local", "unreliable")
|
||
|
func set_rotation_x(x: float):
|
||
|
camera_mount.rotation.x = x
|
||
|
|
||
|
@rpc("any_peer", "call_local", "unreliable")
|
||
|
func set_rotation_y(y: float):
|
||
|
shared_node.rotation.y = y
|