ROBLOX Base Wars’ Low-lag Weapon Design

April

04, 2012

by Andrew Haak


Archive

ROBLOX Base Wars Weapons

Last week, ROBLOX introduced version 1.0 of Base Wars FPS. As promised in the post, Luke Weber is spilling the beans on how he achieved its fast-paced, first-person-shooter feel using raycasting techniques and a couple crafty scripts.

Low-lag weapons

First-person shooters (FPS) rely on solid, responsive shooting. Before Luke even started constructing the weapons, he decided to take advantage of raycasting, which is the use of a function or algorithm to mathematically determine where a ray – or a weapon’s bullet, in Base Wars’ case – hits an object. Raycasting was the obvious choice for several reasons: it’s a quick, efficient and consistent alternative to the old method of firing a projectile, and it allows for instantaneous shooting (a trademark of most FPSs on the market). Better yet, raycasting gave him a foundation of code he could use for other weapons, only having to tweak certain variables to change the effect.

Since ROBLOX Base Wars was originally a paintball game, Luke considered segmenting the raycast to create the effect of a shot actually flying through the air. This ended up detracting from the game’s FPS feel, so he nixed the idea.

Implementation

Luke has scripted a lot of weapons for ROBLOX. He has access to his and the community’s pool of resources, meaning the equipped, unequipped, reloading and ammo-holding styles already existed. There wasn’t any obvious code for him to innovate or improve.

Base Wars Target Practice

Instead, he spent time experimenting with Base Wars’ weapons to find out whether they performed best when running on the user’s computer or the ROBLOX server. With everything running on the user’s computer (i.e., client-side), the weapons were smooth and exact. However, there were bugs that arose from the delay of information between players and the server. Players could shoot other players around corners, and we even noticed players shooting after they were killed.

Those are major problems, and two reasons why Luke decided to try running the weapons on the ROBLOX server (i.e., server-side) for the next test. That caused problems, too, including the one thing that’ll doom (get it?) any FPS: lag.

Luke’s solution was to split the duties between the user’s computer and the ROBLOX server for Base Wars 1.0.

“I finally decided on running the user interface on the user’s computer, and the raycasting on the game server,” Luke said. “I have a client-side script run everything but the raycast. The client-side script actually tells the server-side script to cast rays when needed.”

Base Wars Weapon Code SnippetTranslation?

The guns feel silky smooth. There’s a bit of trigger lag, since the server is processing the weapons, but it’s hardly perceivable. This solution makes the matches fair because there aren’t any weapon bugs to exploit, and the gameplay remains quick and responsive.

Since ROBLOX Base Wars is not copy-locked, advanced users can browse and potentially re-use Luke’s code. He does admit that it’s complicated, so you might only want to download and enter if you’re sure your coding skills are up to snuff.