fully sync player movements over network
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
extends Node3D
|
||||
|
||||
const CONFIG_PATH = "weapons.cfg"
|
||||
const WEAPON_SCENE = preload("res://entities/Weapon.scn")
|
||||
|
||||
@export var player_root : CharacterBody3D
|
||||
@onready var player_root = get_node("../../..")
|
||||
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
|
||||
#@onready var crosshair = $Crosshair
|
||||
|
||||
@@ -15,50 +16,53 @@ var current_weapon = null
|
||||
var mouse_mov : Vector3
|
||||
var sway_lerp = 5
|
||||
|
||||
func _ready():
|
||||
get_tree().get_current_scene().game_loaded.connect(init)
|
||||
|
||||
func init():
|
||||
func _ready():
|
||||
var config = Runtimeloader.loadConfig(CONFIG_PATH) as ConfigFile
|
||||
if(config == null):
|
||||
return
|
||||
|
||||
Init_Config(config)
|
||||
|
||||
var init_config = get_tree().get_current_scene().init_config
|
||||
|
||||
var init_config = get_node("/root/Game").init_config
|
||||
for w_name in init_config.get_value("PLAYER", "starting_weapons"):
|
||||
GiveWeapon(w_name)
|
||||
|
||||
|
||||
func GiveWeapon(weapon_name):
|
||||
if weapon_name in ALL_WEAPONS and not ALL_WEAPONS[weapon_name] in weapons:
|
||||
weapons.append(ALL_WEAPONS[weapon_name])
|
||||
ChangeWeapon(posmod(current_weapon_index, weapons.size()))
|
||||
ChangeWeapon((posmod(current_weapon_index, weapons.size())))
|
||||
|
||||
func TakeWeapon(weapon_name):
|
||||
if weapon_name in ALL_WEAPONS and ALL_WEAPONS[weapon_name] in weapons:
|
||||
weapons.erase(ALL_WEAPONS[weapon_name])
|
||||
ChangeWeapon(posmod(current_weapon_index, weapons.size()))
|
||||
ChangeWeapon((posmod(current_weapon_index, weapons.size())))
|
||||
|
||||
|
||||
func _input(event):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
|
||||
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_T:
|
||||
GiveWeapon("CHAINSAW")
|
||||
|
||||
func _unhandled_input(_event):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
|
||||
if(weapons.size() == 0):
|
||||
return
|
||||
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
|
||||
ChangeWeapon(posmod((current_weapon_index + 1),weapons.size()))
|
||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
|
||||
ChangeWeapon(posmod(current_weapon_index - 1,weapons.size()))
|
||||
ChangeWeapon(posmod((current_weapon_index - 1),weapons.size()))
|
||||
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
current_weapon.Reload()
|
||||
|
||||
|
||||
func ChangeWeapon(i):
|
||||
if(current_weapon):
|
||||
current_weapon.hide()
|
||||
@@ -74,7 +78,10 @@ func ChangeWeapon(i):
|
||||
raycast.target_position.z = -current_weapon.RAY_LEN
|
||||
|
||||
var time = 0
|
||||
|
||||
func _process(delta):
|
||||
if not player_root.is_local_authority():
|
||||
return
|
||||
if(current_weapon == null):
|
||||
return
|
||||
|
||||
@@ -119,9 +126,9 @@ func Projectile():
|
||||
|
||||
func Init_Config(config):
|
||||
for weapon in config.get_sections():
|
||||
var root = Weapon.new()
|
||||
var root = WEAPON_SCENE.instantiate()
|
||||
root.name = weapon
|
||||
|
||||
|
||||
var model_path = config.get_value(weapon, "MODEL") as String
|
||||
var weapon_model
|
||||
if(model_path.ends_with(".glb") or model_path.ends_with(".gltf")):
|
||||
|
||||
Reference in New Issue
Block a user