Fresh start: replace with naxIO/netfox-cs-sample foundation
Complete replacement of the tactical-shooter project with the netfox-cs-sample (MIT) — a CS 1.6 inspired multiplayer FPS built with Godot 4 and netfox. ## What's new - Full CS-style gameplay: teams (T/CT), rounds, economy, buy menu - 6 weapons: Knife, Glock, USP, AK-47, M4A1, AWP - Bomb plant/defuse with 2 bombsites - Flashbang & smoke grenades - Proper netfox rollback netcode at 64 tick - Network popup UI for host/join - HUD, crosshair, round timer, scoreboard - All netfox singletons registered as autoloads (works in exported builds) ## Architecture - Listen-server (host from client, no dedicated server binary) - Multiplayer-fps game lives at examples/multiplayer-fps/ - Netfox addons registered as autoloads for exported build compat - Godot 4.7 with Forward+ renderer ## Removed - Old headless-server architecture (client_main, server_main, player.gd, etc.) - Custom netfox bootstrap with ENet fallback - Old ChaffGames FPS template (2,420 lines, 844 KB) - SimulationServer GDExtension stub - Godot-jolt physics (netfox sample uses default Godot physics) - Duplicate weapon_data.gd, anti_cheat.gd, round_manager.gd, etc. - Server browser API Python venv (87 MB) - test_range map and modular assets ## Preserved - Git history - Server config at config/default_server_config.cfg - Windows export preset - Build directory (gitignored) Co-authored-by: naxIO <naxIO@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# Rollback NPC example
|
||||
|
||||
A demo game, demonstrating how to implement server-controlled NPCs that
|
||||
participate in rollback.
|
||||
|
||||
With `RollbackSynchronizer` supporting no input, NPCs ( and other nodes without
|
||||
input ) can be built the same way as e.g. player nodes.
|
||||
|
||||
To edit and/or run, open the Godot project in the repository root, and open the
|
||||
scene in this directory.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://cg0vfsftxxwv0"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cngy6hs8ohodj" path="res://examples/shared/scenes/map-square.tscn" id="1_os5l0"]
|
||||
[ext_resource type="PackedScene" uid="uid://cncdbq72u50j3" path="res://examples/shared/scenes/environment.tscn" id="2_and7e"]
|
||||
[ext_resource type="Script" path="res://examples/shared/scripts/player-spawner.gd" id="3_1ga2x"]
|
||||
[ext_resource type="PackedScene" uid="uid://badtpsxn5lago" path="res://examples/shared/ui/network-popup.tscn" id="3_1tn81"]
|
||||
[ext_resource type="PackedScene" uid="uid://bl30av5bcvd4d" path="res://examples/rollback-npc/scenes/player.tscn" id="4_pr3ur"]
|
||||
[ext_resource type="PackedScene" uid="uid://n5t5ahafwaln" path="res://examples/rollback-npc/scenes/npc.tscn" id="6_3tc5x"]
|
||||
|
||||
[node name="rollback-npc" type="Node3D"]
|
||||
|
||||
[node name="Square Map" parent="." instance=ExtResource("1_os5l0")]
|
||||
|
||||
[node name="Environment" parent="." instance=ExtResource("2_and7e")]
|
||||
|
||||
[node name="Player Spawner" type="Node" parent="." node_paths=PackedStringArray("spawn_root")]
|
||||
script = ExtResource("3_1ga2x")
|
||||
player_scene = ExtResource("4_pr3ur")
|
||||
spawn_root = NodePath(".")
|
||||
|
||||
[node name="UI" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Network Popup" parent="UI" instance=ExtResource("3_1tn81")]
|
||||
layout_mode = 1
|
||||
offset_left = -180.0
|
||||
offset_top = -120.0
|
||||
offset_right = 180.0
|
||||
offset_bottom = 120.0
|
||||
|
||||
[node name="NPC" parent="." instance=ExtResource("6_3tc5x")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 1, -6)
|
||||
@@ -0,0 +1,51 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://n5t5ahafwaln"]
|
||||
|
||||
[ext_resource type="Script" path="res://examples/rollback-npc/scripts/npc.gd" id="1_6wds5"]
|
||||
[ext_resource type="Script" path="res://addons/netfox/rollback/rollback-synchronizer.gd" id="2_a8m5g"]
|
||||
[ext_resource type="Script" path="res://addons/netfox/tick-interpolator.gd" id="3_ql8cj"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_3ov8j"]
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_tsqs5"]
|
||||
top_radius = 0.0
|
||||
height = 0.5
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2yxbx"]
|
||||
height = 1.5
|
||||
|
||||
[node name="NPC" type="CharacterBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_6wds5")
|
||||
|
||||
[node name="Mesh" type="Node3D" parent="."]
|
||||
|
||||
[node name="Body" type="MeshInstance3D" parent="Mesh"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.25, 0)
|
||||
mesh = SubResource("SphereMesh_3ov8j")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Hat" type="MeshInstance3D" parent="Mesh"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
mesh = SubResource("CylinderMesh_tsqs5")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_2yxbx")
|
||||
|
||||
[node name="RollbackSynchronizer" type="Node" parent="." node_paths=PackedStringArray("root")]
|
||||
script = ExtResource("2_a8m5g")
|
||||
root = NodePath("..")
|
||||
enable_prediction = true
|
||||
state_properties = Array[String]([":position", ":velocity"])
|
||||
|
||||
[node name="TickInterpolator" type="Node" parent="." node_paths=PackedStringArray("root")]
|
||||
script = ExtResource("3_ql8cj")
|
||||
root = NodePath("..")
|
||||
properties = Array[String]([":position"])
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
billboard = 1
|
||||
text = "NPC"
|
||||
font_size = 96
|
||||
@@ -0,0 +1,37 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://bl30av5bcvd4d"]
|
||||
|
||||
[ext_resource type="Script" path="res://examples/rollback-npc/scripts/player.gd" id="1_d0kje"]
|
||||
[ext_resource type="Script" path="res://examples/rollback-npc/scripts/player-input.gd" id="2_us2sq"]
|
||||
[ext_resource type="Script" path="res://addons/netfox/rollback/rollback-synchronizer.gd" id="3_bf3yl"]
|
||||
[ext_resource type="Script" path="res://addons/netfox/tick-interpolator.gd" id="4_4lenk"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bmc6p"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_t0alo"]
|
||||
material = SubResource("StandardMaterial3D_bmc6p")
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1dm6n"]
|
||||
|
||||
[node name="Player" type="CharacterBody3D" groups=["Players"]]
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_d0kje")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CapsuleMesh_t0alo")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_1dm6n")
|
||||
|
||||
[node name="Input" type="Node" parent="."]
|
||||
script = ExtResource("2_us2sq")
|
||||
|
||||
[node name="RollbackSynchronizer" type="Node" parent="." node_paths=PackedStringArray("root")]
|
||||
script = ExtResource("3_bf3yl")
|
||||
root = NodePath("..")
|
||||
state_properties = Array[String]([":transform", ":velocity"])
|
||||
input_properties = Array[String](["Input:movement"])
|
||||
|
||||
[node name="TickInterpolator" type="Node" parent="." node_paths=PackedStringArray("root")]
|
||||
script = ExtResource("4_4lenk")
|
||||
root = NodePath("..")
|
||||
properties = Array[String]([":transform"])
|
||||
@@ -0,0 +1,76 @@
|
||||
@tool
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var speed: float = 2.0
|
||||
@export var sensor_radius: float = 4.0
|
||||
@export var min_radius: float = 1.5
|
||||
|
||||
@onready var label := $Label3D as Label3D
|
||||
@onready var rbs := $RollbackSynchronizer as RollbackSynchronizer
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting(&"physics/3d/default_gravity")
|
||||
|
||||
func _get_rollback_state_properties() -> Array:
|
||||
return [
|
||||
"position",
|
||||
"velocity"
|
||||
]
|
||||
|
||||
func _get_interpolated_properties() -> Array:
|
||||
return [
|
||||
"position"
|
||||
]
|
||||
|
||||
func _rollback_tick(dt, _tick, _is_fresh: bool):
|
||||
label.text = "pre" if rbs.is_predicting() else "sim"
|
||||
|
||||
# Add gravity
|
||||
_force_update_is_on_floor()
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * dt
|
||||
|
||||
var target_motion := Vector3.ZERO
|
||||
var nearby_player := _find_nearby_player()
|
||||
if nearby_player:
|
||||
target_motion = nearby_player.global_position - global_position
|
||||
target_motion.y = 0.
|
||||
|
||||
target_motion = target_motion.normalized() * speed
|
||||
|
||||
velocity.x = move_toward(velocity.x, target_motion.x, speed / 0.35 * dt)
|
||||
velocity.z = move_toward(velocity.z, target_motion.z, speed / 0.35 * dt)
|
||||
|
||||
# move_and_slide assumes physics delta
|
||||
# multiplying velocity by NetworkTime.physics_factor compensates for it
|
||||
velocity *= NetworkTime.physics_factor
|
||||
move_and_slide()
|
||||
velocity /= NetworkTime.physics_factor
|
||||
|
||||
func _find_nearby_player() -> Node3D:
|
||||
var players := get_tree().get_nodes_in_group(&"Players")
|
||||
if players.is_empty():
|
||||
return null
|
||||
|
||||
var sensor_radius_squared := pow(sensor_radius, 2.0)
|
||||
var min_radius_squared := pow(min_radius, 2.0)
|
||||
|
||||
var closest_player: Node3D = null
|
||||
var closest_distance := INF
|
||||
for player in players:
|
||||
var distance := global_position.distance_squared_to(player.global_position)
|
||||
|
||||
if distance >= sensor_radius_squared or distance <= min_radius_squared:
|
||||
continue
|
||||
|
||||
if distance < closest_distance:
|
||||
closest_distance = distance
|
||||
closest_player = player
|
||||
|
||||
return closest_player
|
||||
|
||||
func _force_update_is_on_floor():
|
||||
var old_velocity = velocity
|
||||
velocity = Vector3.ZERO
|
||||
move_and_slide()
|
||||
velocity = old_velocity
|
||||
@@ -0,0 +1 @@
|
||||
uid://7ru5vkblxide
|
||||
@@ -0,0 +1,16 @@
|
||||
@tool
|
||||
extends BaseNetInput
|
||||
|
||||
var movement: Vector3
|
||||
|
||||
func _get_rollback_input_properties() -> Array:
|
||||
return [
|
||||
"movement"
|
||||
]
|
||||
|
||||
func _gather():
|
||||
movement = Vector3(
|
||||
Input.get_axis("move_west", "move_east"),
|
||||
0.0,
|
||||
Input.get_axis("move_north", "move_south")
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://brtfiqnk5alw6
|
||||
@@ -0,0 +1,65 @@
|
||||
@tool
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var speed = 5.0
|
||||
@export var input: Node
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting(&"physics/3d/default_gravity")
|
||||
|
||||
func _get_rollback_state_properties() -> Array:
|
||||
return [
|
||||
"transform",
|
||||
"velocity"
|
||||
]
|
||||
|
||||
func _get_interpolated_properties() -> Array:
|
||||
return [
|
||||
"transform"
|
||||
]
|
||||
|
||||
func _ready():
|
||||
if Engine.is_editor_hint(): return
|
||||
|
||||
if input == null:
|
||||
input = $Input
|
||||
|
||||
position = Vector3(0, 4, 0)
|
||||
|
||||
# Assign a random color
|
||||
var player_id := input.get_multiplayer_authority()
|
||||
var mesh := $MeshInstance3D as MeshInstance3D
|
||||
|
||||
var color := Color.from_hsv((hash(player_id) % 256) / 256.0, 1.0, 1.0)
|
||||
var material := mesh.get_active_material(0) as StandardMaterial3D
|
||||
material = material.duplicate()
|
||||
material.albedo_color = color
|
||||
mesh.set_surface_override_material(0, material)
|
||||
|
||||
func _rollback_tick(dt, _tick, _is_fresh: bool):
|
||||
# Add gravity
|
||||
_force_update_is_on_floor()
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * dt
|
||||
|
||||
var input_dir = input.movement
|
||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.z)).normalized()
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
velocity.z = move_toward(velocity.z, 0, speed)
|
||||
|
||||
# move_and_slide assumes physics delta
|
||||
# multiplying velocity by NetworkTime.physics_factor compensates for it
|
||||
velocity *= NetworkTime.physics_factor
|
||||
move_and_slide()
|
||||
velocity /= NetworkTime.physics_factor
|
||||
|
||||
func _force_update_is_on_floor():
|
||||
var old_velocity = velocity
|
||||
velocity = Vector3.ZERO
|
||||
move_and_slide()
|
||||
velocity = old_velocity
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://cn33wgc64tn4k
|
||||
Reference in New Issue
Block a user