Init commit
This commit is contained in:
28
godot/scenes/player/placeholder.gd
Normal file
28
godot/scenes/player/placeholder.gd
Normal file
@ -0,0 +1,28 @@
|
||||
extends CharacterBody3D
|
||||
class_name ServerNode
|
||||
|
||||
var jumping := false
|
||||
var input_direction: Vector2 = null
|
||||
var owner_id: int = 0
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
if is_on_floor() && jumping:
|
||||
velocity.y = const .
|
||||
|
||||
#if shooting:
|
||||
jumping = false
|
||||
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
#first_view_legs_anim.play("Run Forward")
|
||||
velocity.x = direction.x * character_speed
|
||||
velocity.z = direction.z * character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, character_speed)
|
32
godot/scenes/player/placeholder.tscn
Normal file
32
godot/scenes/player/placeholder.tscn
Normal file
@ -0,0 +1,32 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://3m22sdln5238"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/placeholder.gd" id="1_djt0m"]
|
||||
[ext_resource type="PackedScene" uid="uid://ddwrs0so7swxn" path="res://scenes/characters/y-bot/character.tscn" id="2_a22jl"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1v0rt"]
|
||||
height = 1.8
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_43f22"]
|
||||
properties/0/path = NodePath(".:owner_id")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath(".:position")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
|
||||
[node name="PlayerPlaceholder" type="PlayerPlaceholder"]
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
script = ExtResource("1_djt0m")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0)
|
||||
shape = SubResource("CapsuleShape3D_1v0rt")
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_43f22")
|
||||
|
||||
[node name="BulletStartingPoint" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.76042, -0.28729)
|
||||
|
||||
[node name="Character" parent="." instance=ExtResource("2_a22jl")]
|
22
godot/scenes/player/player_input.tscn
Normal file
22
godot/scenes/player/player_input.tscn
Normal file
@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dqp551myngaey"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/player_input_controller.gd" id="1_5vm0e"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_uacs5"]
|
||||
|
||||
[node name="PlayerInput" type="CharacterBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_5vm0e")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("CapsuleShape3D_uacs5")
|
||||
|
||||
[node name="CameraMount" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.70665, -0.197926)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CameraMount"]
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.70817, 0)
|
72
godot/scenes/player/player_input_controller.gd
Normal file
72
godot/scenes/player/player_input_controller.gd
Normal file
@ -0,0 +1,72 @@
|
||||
# ---------------------------------------------------------------------
|
||||
# This script is supposed to control the node that is rendered on the
|
||||
# client side, and send the changes to the server node
|
||||
# ---------------------------------------------------------------------
|
||||
extends CharacterBody3D
|
||||
class_name PlayerInputController
|
||||
|
||||
var jumping: bool = false
|
||||
var shooting: bool = false
|
||||
var moving: bool = false
|
||||
var look_dir: Vector2
|
||||
var input_direction := Vector2()
|
||||
var camera_sens: float = 0.002
|
||||
|
||||
const JUMP_VELOCITY = 4.5
|
||||
var character_speed: int = 5
|
||||
|
||||
var controlled_node: PlayerPlaceholder = null
|
||||
@export var owner_id: int = 0
|
||||
|
||||
@onready var camera_mount = $CameraMount
|
||||
func _ready() -> void:
|
||||
set_multiplayer_authority(multiplayer.get_unique_id())
|
||||
global_position = controlled_node.global_position
|
||||
rotation = controlled_node.rotation
|
||||
|
||||
func _input(event):
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
if Input.is_action_just_pressed("jump"): jump()
|
||||
if Input.is_action_just_released("shoot"): shooting = false
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
look_dir = event.relative * 1
|
||||
rotation.y -= look_dir.x * camera_sens * 1.0
|
||||
camera_mount.rotation.x = clamp(camera_mount.rotation.x - look_dir.y * camera_sens * 1.0, -1.5, 1.5)
|
||||
controlled_node.set_rotation_x.rpc_id(1, rotation.x)
|
||||
controlled_node.set_rotation_y.rpc_id(1, rotation.y)
|
||||
if Input.is_action_pressed("move_left") or Input.is_action_pressed("move_right") or Input.is_action_pressed("move_forward") or Input.is_action_pressed("move_backwards"):
|
||||
moving = true
|
||||
else:
|
||||
moving = false
|
||||
|
||||
func jump():
|
||||
jumping = true
|
||||
controlled_node.jump.rpc_id(1)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
input_direction = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
controlled_node.set_input_direction.rpc_id(1, input_direction)
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
if is_on_floor() && jumping:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
#if shooting:
|
||||
jumping = false
|
||||
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
#first_view_legs_anim.play("Run Forward")
|
||||
velocity.x = direction.x * character_speed
|
||||
velocity.z = direction.z * character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, character_speed)
|
||||
#controlled_node.sync_velocity.rpc_id(1, velocity.x, velocity.y, velocity.z)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
move_and_slide()
|
12
godot/scenes/player/server_node.tscn
Normal file
12
godot/scenes/player/server_node.tscn
Normal file
@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cse87uxvcvhee"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/placeholder.gd" id="1_cs2mj"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_82tpl"]
|
||||
|
||||
[node name="ServerNode" type="CharacterBody3D"]
|
||||
script = ExtResource("1_cs2mj")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("CapsuleShape3D_82tpl")
|
Reference in New Issue
Block a user