Hey Roblox Developers!
I’m localModuled, and I’m excited to introduce you to LocalCast.
LocalCast is an easy-to-use module that enables smooth bullet projectiles and correct server-side hitboxes.
-
How does LocalCast ensure accurate server-side hitboxes, and how does it handle this?
When using server-side hitboxes, you might encounter issues where the client and server don’t sync correctly. For example, your client might show that you hit an opponent, but the server might not register it. This discrepancy happens because players are constantly moving, and the server struggles to keep up with these changes due to latency.
Example:
LocalCast solves this problem with a custom ‘Recorder’ system that I developed. This system records every frame for up to the last 2.5 seconds, ensuring precise hitbox detection and minimizing inconsistencies between the client and server.
Here’s how it works: When a client sends a projectile request to the server, it also includes the client’s timestamp. The server receives this timestamp and simulates the game state from that moment in the past. By recreating the hitboxes and simulating the frames from that point forward, the server aligns its view with what the client saw. This approach effectively resolves discrepancies and ensures that the hitboxes perceived by the client match what the server detects.
So, no more desynchronized projectiles!
Using LocalCast is incredibly straight forward. It’s possibly one of the simplest things you’ll encounter. All you need to do is require the module and call LocalCast.new()
.
When you create a new LocalCast instance, here’s what you can access on either the server or client:
local LocalCastModule = require(ReplicatedStorage.LocalCast)
--If you are using on Client for example.
local LocalCast = LocalCastModule.new("IdExampleWeapons")
--If you are using on Server for example.
local LocalCast = LocalCastModule.new("IdExampleWeapons", function(player, origin, direction, projectileData, tag)
--[[ Check here for the server authorize. Example: checking ammo
local AmmoAmount = 2
if AmmoAmount > 0 then
return true
end
]]
return true --or false
end)
LocalCast.OnHit:Connect(OnHit) -- instance, position, projectileData
LocalCast.OnDistanceReached:Connect(OnDistanceReached) -- position, projectileData
LocalCast.OnDistanceChanged:Connect(OnDistanceChanged) -- position, distanceTraveled, projectileData
LocalCast.OnDestroy:Connect(OnDestroy) -- position, projectileData
- OnHit: Triggered when the projectile hits something, providing the instance, position, and projectile data.
- OnDistanceReached: Triggered when the projectile reaches its ‘MaximumDistance’ without hitting anything.
- OnDistanceChanged: Fires every frame when the projectile’s position changes.
- OnDestroy: Triggered when the LocalCast instance is destroyed.
To create a projectile, simply call the LocalCast:Create
command. Here’s an example:
LocalCast:Create(Origin, Direction, {
Velocity = 500,
BulletModel = ExampleBulletModelPath,
--[[ Optional parameters:
RaycastParam = RaycastParams,
Gravity = Vector3.new(0, -98.1, 0),
MaxDistance = 2500,
MetaData = {
-- Any custom data to send with the projectile. For example:
Damage = 20, -- Accessed via projectileData.MetaData.Damage
},
]]
})
LocalCast handles the client-side simulation of projectile models automatically. When you create a projectile on the client, a request is sent to the server. If the server approves the request, it will broadcast it to other clients, allowing them to simulate the projectile. This means you don’t need to manually set up RemoteEvents or other networking; simply call Create
from the client.
Here is an example roblox place LocalCast Example Place - Roblox
To get LocalCast on library LocalCast
The module is still under development and open to any suggestions, so feel free to ask questions or share your ideas!
LocalCast used in Blade Blitz! game.
Version 1.0.2