So to specify my issue. I have a gun system in my game that uses raycasting. I use raycast result position and normal to position the bullet holes on a player when they get shot. However since the shots are determined on the client the replication acts up sometimes. So if I shoot a player and the bullet hole is placed using ray result position and normal sometimes the bullet hole will just be floating near where they got shot and not directly on them. How can I fix this?
To simplify the issue. How can I use the raycast result and raycast normal almost like a “Part Offset” so that I can always place the bullet hole in the right spot on a part / limb even if its cframe / position changes.
My game has injuries so the bullet holes are a must. And I already weld them. The issue is the rcpos and normal are determined and then it fires an event to the server which has a very slight delay which can result in the bullet hole floating.
you can use cframe:ToObjectSpace(cframe) to get the offset and send it to server
--// Client //--
local instance = raycastResult.Instance
local position = raycastResult.Position
local normal = raycastResult.Normal
local offset = CFrame.new(position):ToObjectSpace(instance.CFrame)
local cframe = CFrame.new(position, position + normal)
local offset = instance.CFrame:ToObjectSpace(cframe)
event:FireServer(offset, raycastResult.Instance)
--// Server //--
event.OnServerEvent:Connect(function(player, offset, instance)
local cframe = instance.CFrame * offset
bulletHole.CFrame = instance.CFrame * offset
end)
Not only does it appear weirdly. Its always facing forward so if I shoot the player in the back the decal for the bullethole is going to hidden since the front face is going to be the same as the part it hit.