im using fastcast to get the bullets moving and the real projectile is on the server doing all the hit detection and i fire to all the clients with the same origin and direction to actually render the bullet
but the bullet doesnt come from the barrel like it should instead it starts with its center in the barrel
video:
update code:
function RayUpdated(cast, origin, direction, length, velocity, bullet)
if bullet == nil then return end
local bulletLength = bullet.Size.Z
bullet.CFrame = CFrame.lookAt(origin, origin + direction) * CFrame.new(0, 0, -(length - bulletLength))
end
the bullet is a 0.1 by 0.1, by 88.7 sphere mesh
i want it to look like this
(this image uses different code, anything closer than 88.7 studs wont show the bullet so i just use a raycast for it)
the bullet should start from the barrel and move out until it reaches 88.7 studs long then it should stop touching the barrel
do you know how to fix it?
the server saids i should ricochet but fastcast is breaking
code:
function CanRayPierce(cast, result, velocity)
local material = string.split(tostring(result.Material), ".")[3]
local percent = ricochet[material]
local id = cast.UserData.BulletID
print(allowedRicochet[id])
if percent then
local chance = random:NextInteger(1, 100)
if chance <= percent or allowedRicochet[id] ~= nil then
if allowedRicochet[id] ~= nil then
allowedRicochet[id] = nil
end
return true
end
end
return false
end
function RayPierced(cast, result, velocity, bullet)
local owner = cast.UserData.Owner
local id = cast.UserData.BulletID
local settings = cast.UserData.Properties
local blackList = cast.UserData.BlackList
if settings.explosive then return end
local position = result.Position
local normal = result.Normal
bullet.Size = Vector3.new(bullet.Size.X, bullet.Size.Y, bullet.Size.Z / 2)
velocity /= 2
local newNormal = Reflect(normal, velocity.Unit)
cast:SetVelocity(newNormal * velocity.Magnitude)
cast:SetPosition(position)
end
allowedricochet[id] will be true if the server said i should ricochet (this is for when the bullet is very close to the wall when fired and it wont show so i had to use a different method to show it and the ricochet is different
so… i changed a lot with the piercing function of fastcast and now this doesnt work anymore
sometimes it will come from the barrel and sometimes it wont
i did move the bullet rendering to the server due to the new piercing functions so that may be why
fire code:
local cast = caster:Fire(
origin,
direction * 5000,
shellType.speed,
behavior
)
cast.UserData.Origin = origin
cast.UserData.Direction = direction
cast.UserData.Owner = plr
cast.UserData.BulletID = id
cast.UserData.Properties = settings
cast.UserData.BlackList = customList
cast.UserData.ShellType = shellType
update code:
function RayUpdated(cast, origin, direction, length, velocity, bullet)
if bullet == nil then return end
local bulletLength = bullet.Size.Z
local pos = origin + direction * bulletLength / 2
bullet.CFrame = CFrame.new(pos, pos + direction)
end
video:
edit: i changed the update code to:
function RayUpdated(cast, origin, direction, length, velocity, bullet)
if bullet == nil then return end
local bulletLength = bullet.Size.Z
local pos = origin + direction * -(length - (bulletLength / 2))
bullet.CFrame = CFrame.new(pos, pos + direction)
end
now when it isnt coming from the barrel its just slightly off so ill deal with it for now but if anyone has a way for it to always be coming from the barrel tell me please