How the Volleyball Script Works

4 min read

View Volleyball Script in the WXMAPS store

How It Works

You do not need this page to run the script. It is here because "physics-driven multiplayer ball" is a claim, and this is what is behind it.

The ball is not a networked entity

Almost every ball in FiveM is a physical prop owned by one client, with everyone else watching a synchronised copy. That is where the jitter, the ownership hitches and the "it went through the net on my screen" come from, and it is why the client that owns the ball can tell the server whatever it likes about where it went.

This one works the other way round:

  1. The server holds the ball's math state and nothing else, no entity, no prop.
  2. On each discrete event (serve, hit, bounce, net, point) it broadcasts a tiny segment: a position, a velocity and a start time.
  3. The server and every client run the same integrator from that segment.
  4. Each client moves a purely local prop along the arc it computed.

Everyone renders an identical trajectory from a few bytes per event. There is nothing to desync between events, because between events nothing is sent.

Server authority

  • The server steps the ball and detects ground, net and out events itself.
  • It runs the rules state machine and the scoring.
  • It validates every hit against its own authoritative ball position.

A client cannot score a point the server did not see.

The client offers, the server decides

Which shot you play is a trajectory decision wearing an animation costume: a spike and a bump are different speeds and different launch angles (spike 15.0 m/s at 16°, set 8.5 at 46°, bump 9.5 at 42°). So the shot rule is not a client decision the server rubber-stamps.

Your client reads the rule, shows you the prompt and sends its answer as an offer. The server asks the same rule of its own copy of your position and takes its own answer, honouring yours only where the difference fits inside one round trip of uncertainty. Where the two disagree, an echo-replay path re-plays the shot the server actually chose, so what you see is what happened.

Clock sync

Clients run an NTP-style offset handshake against the server, so every machine samples the trajectory on the server's timeline rather than its own. Two players on very different pings see the ball in the same place at the same moment.

The ball hits things

The integrator flies a ball through empty air, which is all the rule ever needs: the server decides a rally at the first floor or net crossing and never asks again. A separate bounce model owns what happens after that: the ball bounces on the sand, rolls and goes to sleep, and a ball ruled into the net stops against it and drops at its foot instead of sailing through the mesh.

Sand restitution is speed-dependent, because a granular bed absorbs proportionally more the harder it is struck: a dropped ball bounces visibly while a spike kicks up under a metre and dies. It costs no extra networking; it runs off the same segment, and it is bit-identical to the plain integrator until the first contact, which is the crossing the server has already scored. No scoring changed: it is presentation.

The ball leaves when the hand arrives

A serve that launches on the keypress looks wrong: the ball leaves before the animation has swung. The script knows, per clip, when the ball meets the body (measured off the source animation, not guessed) and dates the segment's start time to that strike frame. The ball parks on the hand on every machine and launches in sync at the frame the hand reaches it. No re-broadcast, no latency pop.

Where a clip has no measured contact frame, the ball launches at the hit exactly as it always did. Those numbers are measurements or they are absent; none of them is a placeholder, and the module refuses to load if a row carries a contact number without a citation.

Animations

The action vocabulary is a delivered custom mocap library streamed with the resource: serves, spikes, sets, overhead passes, bumps, steps, digs, blocks, footwork and ready stances, with per-bearing variants so a ped playing a ball to its left uses the left clip. Gameplay code calls actions by name (spike, bump), never a clip directly.

What this buys you

  • No ownership transfer, so no hitch when the ball crosses the net.
  • Near-zero bandwidth: events, not a stream of positions.
  • Identical arcs on every client, including the audience standing around the court.
  • Scoring that cannot be faked from a client.