Physics support for combat system ; Map collider system#2
Merged
PiscesTrio merged 13 commits intomainfrom Feb 18, 2026
Merged
Conversation
Add header-only server collision system and integrate it into the game server, plus add a CI workflow to build/push a dev Docker image. - New GitHub Actions workflow (.github/workflows/docker-build-dev.yml) to build and push dev images on pushes to the dev branch. - New Network/server_collision.h: header-only capsule vs AABB resolution utilities (ClosestPointOnSegment, ClampToAABB, ResolveCapsule). Returns corrected position/velocity and grounded state; must be kept in sync with client collision logic. - Network/game_server.h: include server_collision.h, add m_Colliders vector and player collision constants (PLAYER_HEIGHT, CAPSULE_RADIUS). - Network/game_server.cpp: initialize simple world colliders (ground + test platform) in Initialize(); replace ad-hoc floor logic in SimulatePlayerPhysics with ServerCollision::ResolveCapsule and preserve fallback floor behavior when no colliders present. Collision response updates position, velocity, and grounded/jumping flags. These changes enable deterministic server-side player collision and provide a CI step to publish development Docker images. Adjust collider data and tuning constants as needed to match client behavior.
In SimulatePlayerPhysics (Network/game_server.cpp), add an else branch to clear the NetStateFlags::IS_GROUNDED flag when the player is not grounded. This prevents the grounded flag from persisting incorrectly across frames and ensures accurate grounded/jumping state transitions.
Only set IS_GROUNDED when the collider reports grounded and the vertical velocity is non-positive (state.velocity.y <= 0.0f). Also only clear IS_GROUNDED when result.isGrounded is false, preventing spurious loss of the grounded state during upward velocity (e.g. small bounces or upward corrections). Keeps IS_JUMPING cleared when legitimately grounded.
Record the player's grounded state at the start of physics simulation and use it to decide gravity application so gravity is only applied when the player was airborne at frame start. Simplify grounded/jumping state updates to rely directly on collision results (always set IS_GROUNDED when collision reports grounded and clear JUMPING), avoiding incorrect velocity checks. Also adjust the capsule-vs-AABB test to use > instead of >= so exact tangential contacts (distSq == radius^2) are treated as collisions, fixing boundary miss cases.
Add a shared MapColliderDef array (Network/map_colliders.h) and update GameServer to register colliders from it instead of using hardcoded colliders. The new header defines collider categories (MAP_GROUND, MAP_CUBE, MAP_WALL), a pure-C MapColliderDef struct, MAP_COLLIDERS and MAP_COLLIDER_COUNT for client/server sync. GameServer::Initialize now iterates MAP_COLLIDERS, builds ServerCollider AABBs (auto-computes ±0.5 for MAP_CUBE, uses explicit min/max for others) and copies the isGround flag, removing the previous hardcoded ground/platform entries.
Implements server-authoritative combat: adds health, firing, respawn and hit tracking to player state and logic. net_common.h: introduce IS_DEAD flag, expand NetPlayerState with health, hitByPlayerId and fireCounter and update static_assert sizes. game_server.h: add combat fields, firing/ raycast APIs and weapon constants. game_server.cpp: initialize health/fire/respawn on connect, skip actions for dead players, run per-tick respawn logic, integrate ProcessFiring (RPM/damage, fire timing, fireCounter) and RaycastPlayers (ray->capsule hits against enemies), prevent friendly fire and mark kills; skip dead players during physics; sync combat data into snapshots. Added server_raycast.h: standalone ray-capsule intersection and direction helpers used for server hitscan. These changes enable server-side hitscan, damage application, death/respawn and hit markers.
Lower the player eye offset to PLAYER_HEIGHT - 0.3f (approx. 1.7m) and correct the vertical component sign in DirectionFromYawPitch (use sinf(pitch) instead of -sinf(pitch)). These changes align the ray direction with the pitch convention and improve vertical aiming/hit detection accuracy.
Update player collision constants to match the client model: PLAYER_HEIGHT reduced from 2.0 to 1.6 and CAPSULE_RADIUS from 0.5 to 0.3. Also change the eye position calc in ProcessFiring to use an explicit 1.5f offset (matching the client camera) instead of PLAYER_HEIGHT * 0.75f to keep server hit detection consistent with the client.
Prevent hits through world geometry by testing player raycasts against map colliders. ProcessFiring now computes worldDist via GameServer::RaycastWorld and only applies player damage if the player hit is closer than the world hit. Added GameServer::RaycastWorld (iterates m_Colliders and returns closest hit distance or a large value if none) and declared it in the header. Implemented ServerRaycast::RayAABB in server_raycast.h using the slab method (with a default maxRange = 200) to test ray vs. axis-aligned bounding boxes.
Convert map data to a grid-based layout and simplify collider defs: replace the old MapCategory/cube-based entries with a MAP_GRID, map constants, and merged AABB entries (MAP_COLLIDERS now contains explicit min/max boxes only). Update MapColliderDef to only store explicit AABB + isGround and remove cube auto-AABB handling. Adjust GameServer to read the new colliders (always use the provided AABB) and add <cstdlib> for rand(). Change GetSpawnPosition to pick a random position within one of four corner spawn areas (randomized X/Z per spawn); playerId/teamId are no longer used for deterministic offsets. This reduces server-side complexity and centralizes map geometry, but note spawn behavior is now nondeterministic unless srand is set elsewhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.