When i try to use parts to visualize the FastCast, the parts don’t move at all, they’re frozen in the air
when I’m using it on a NPC
Example video:
This is the code:
local Tool = script.Parent
local Handle = Tool.Handle
local FirePointObject = Handle.GunFirePoint
local FastCast = require(game:GetService("ReplicatedStorage").FastCastRedux)
local GunModule = require(game:GetService("ReplicatedStorage").GunEngine["Thompson"].GunModule)
local soundModule = require(game:GetService("ReplicatedStorage").GunEngine.SoundModule)
local hitModule = require(game:GetService("ReplicatedStorage").GunEngine.HitSounds)
local FireSound = Handle.Fire
local particle = FirePointObject.Fire
local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.FilterDescendantsInstances = {Tool.Parent, bulletsFolder}
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, 0, 0)
castBehavior.AutoIgnoreContainer = true
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = GunModule.CosmeticBullet
wait(.2)
local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0,0,-(length - bulletLength))
bullet = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local function fire(char, mouseposition)
local origin = FirePointObject.WorldPosition
local direction = (mouseposition - origin).Unit
caster:Fire(origin, direction, GunModule.BULLET_SPEED, castBehavior)
end
caster.LengthChanged:Connect(onLengthChanged())
while wait(0.1) do
print("fire")
fire(Tool.Parent, Vector3.new(0,5,0))
end
local Tool = script.Parent
local Handle = Tool.Handle
local FirePointObject = Handle.GunFirePoint
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FastCast = require(ReplicatedStorage.FastCastRedux)
local GunModule = require(ReplicatedStorage.GunEngine["Thompson"].GunModule)
local soundModule = require(ReplicatedStorage.GunEngine.SoundModule)
local hitModule = require(ReplicatedStorage.GunEngine.HitSounds)
local FireSound = Handle.Fire
local particle = FirePointObject.Fire
local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.FilterDescendantsInstances = {Tool.Parent, bulletsFolder}
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.zero
castBehavior.AutoIgnoreContainer = true
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = GunModule.CosmeticBullet
task.wait(.2)
local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0, 0, -(length - bulletLength))
bullet = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
local function fire(char, mouseposition)
local origin = FirePointObject.WorldPosition
local direction = (mouseposition - origin).Unit
caster:Fire(origin, direction, GunModule.BULLET_SPEED, castBehavior)
end
caster.LengthChanged:Connect(onLengthChanged)
while task.wait(0.1) do
print("fire")
fire(Tool.Parent, Vector3.new(0, 5, 0))
end
You should also be using task.wait instead of wait.
local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
local newPosition = lastPoint + direction * length
bullet.Position = newPosition
end