Need help "replicating" velocity using raycast

So the title says it all. I’m trying to synchronize a constantly travelling bullet with a raycast since I use the client in order to create the bullet due to lag. I’ve tried using .Touched with another bullet created on the server’s end which works, but it doesn’t accurately detect when a player is hit.

Does this mean that it doesn’t look to be accurate from the client’s perspective, or that it isn’t triggering the touched event when the ray intersects a player on the server?

[Also, see FastCast if you haven’t.]

You could make multiple ray cast and tween the position, one after the other to make an accurate bullet. And you could give it a bullet drop using something like time()?

Don’t use .Touched, because it’s inaccurate due to client-server network replication.

-- bullets is a table containing all bullet info (i.e the bullet variable is in the bullets array)
-- bullet variable is a table containing info about the bullet!
-- physicalBullet is the physical version of the raycast bullet.
-- bullet.ignoreParams is the Raycast's params.

local bulletPos = bullet.position
local Raycast = workspace:Raycast(bulletPos, bullet.direction, bullet.ignoreParams);

if Raycast then
	explodeRocket(Rocket_, Raycast.Position, Raycast.Distance)
	Rocket_ = nil
	table.remove(bullets, i) -- this is ran in a renderstepped loop because it's on the client, you can use heartbeat if used on the server!
	local newPos = bulletPos + bullet.direction
	Rocket.position = newPos
	physicalBullet.CFrame =, newPos)
	physicalBullet.CFrame = physicalBullet.CFrame:Lerp(physicalBullet.CFrame*CFrame.Angles(0, 0, math.pi/dt), .3)
    -- CFrame.Angles(0, 0, math.pi/dt) is supposed to be the rotation of the physical bullet, you can remove it if you'd like!
1 Like