-
What do you want to achieve? I want my bullet to spawn in the muzzle.
-
What is the issue?
-
What solutions have you tried so far? I was trying to find a solution on the devforum.
How do I make the bullet fly straight out of the muzzle? For now its spawning a little further than necessary.
--Server script
local cast = fastcast.new()
local behavior = fastcast.newBehavior()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {plr.Character}
params.FilterType = Enum.RaycastFilterType.Exclude
behavior.RaycastParams = params
behavior.Acceleration = Vector3.new(0,-workspace.Gravity/2, 0)
behavior.AutoIgnoreContainer = true
behavior.CosmeticBulletTemplate = ReplicatedStorage.Bullets.Bullet
behavior.CosmeticBulletContainer = workspace.Projectiles
cast.LengthChanged:Connect(function(ActiveCast, lastPoint, rayDir, displacement, segmentVelocity, cosmeticBulletObject)
if cosmeticBulletObject then
local bulletLength = cosmeticBulletObject.Size.Z / 2
local offset = CFrame.new(0,0, -(displacement - bulletLength))
cosmeticBulletObject.CFrame = CFrame.lookAt(lastPoint, lastPoint + rayDir):ToWorldSpace(offset)
end
end)
cast.RayHit:Connect(function(ActiveCast, RaycastResult, segmentVelocity, cosmeticBulletObject)
local hit = RaycastResult.Instance
print(hit)
end)
local direction = (mouse-muzzlePos)
cast:Fire(muzzlePos, direction, 300, behavior)