I Have a projectile that move by BodyVelocity, I Want the best way to detect hits rather than using touched event because it is just a piece of junk.
1 Like
raycasting infront of the projectile and cframe moving it
I Tried something like this.
repeat
wait(0.01)
local RaycastResult = workspace:Raycast(Projectile.Position, Direction * 100, RaycastParameters)
if RaycastResult then
if RaycastResult.Instance:IsA("BasePart") then
print((RaycastResult.Position - Projectile.Position).Magnitude)
if (RaycastResult.Position - Projectile.Position).Magnitude <= 1 then
print("Not far.")
Hit = true
end
end
end
until Hit == true
maybe something like this
while task.wait(1/60) do
for _,Bullet in workspace:WaitForChild("Bullets"):GetChildren() do
pcall(function()
movebullet({Bullet = Bullet,Direction = Bullet.CFrame.LookVector})
end)
end
end
end)
function movebullet(Config)
local Bullet = Config.Bullet
local Direction = Config.Direction
local ReturningBool = false
Bullet:AddTag("Moving")
local RayRaycastParams = RaycastParams.new()
RayRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(Bullet.CFrame.Position, Direction * (SettingsBulletVelocity), RayRaycastParams)
local normal = Bullet.CFrame.LookVector
Bullet.Position+=(Direction * SettingsBulletVelocity)
if ray then
-- it hit target
end
return ReturningBool
end
you gotta fill in the blanks stuff