I have been making guns for a game I’m making, but I’m having problems with making the bullet collision with where it’s going work better. Here is a video of what I got robloxapp-20211229-1557379.wmv (1.9 MB)
Don’t mind the lack of animations, I’m not done with that
But, as you can see the hitting of the bullet really isn’t that good, because the bullet just stop before or after it hits the player. Is there a better way for me to tell if the bullet is colliding with something?
here’s my current script for the bullet
local CanHit = true
local Instance_Create = BulletModel:Clone()
CollectionService:AddTag(Instance_Create,"Bullet")
Instance_Create.Parent = parent
Instance_Create.Position = Pos
Instance_Create.CFrame = CFrame.lookAt(Pos,Dist) * Accuracy
Instance_Create.Anchored = false
TweenService:Create(Instance_Create, TweenInfo.new(0.25,Enum.EasingStyle.Linear,Enum.EasingDirection.In), {Velocity = Instance_Create.CFrame.lookVector * Speed}):Play()
Debris:AddItem(Instance_Create,6)
RepEvents:FindFirstChild("BulletReturn"):FireClient(plr, Instance_Create)
Instance_Create.Touched:Connect(function(hit)
if CanHit == true then
if hit and hit.Parent and hit.Parent ~= plr.Character and hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid:TakeDamage(dmg)
Instance_Create.Anchored = true
end
end
end)
This is a server-side script btw.
So is there any better way to get more accurate bullets?
I’m not actually using the line .Anchored = true. I am destroying the bullet after it’s touched. that line is just an example, my main question is, is there a better way to do bullets in roblox. then the way i am doing it
Debris
The Debris Service is the best way to go to avoid any sort of issues with :Destroy() and remove clunkiness with any sort of other system with manually destroying an object
But how would I raycast it I don’t want it to just go so fast that you don’t see it
And i want the ray to follow the bullet but not hit something it’s not yet at
you can use run service to move the ray with the bullet. Also running bullets on server generally is not a good idea. I would recommend replicating the bullets to all clients through a remote event.
local RayTestParams = RaycastParams.new()
RayTestParams.FilterType = Enum.RaycastFilterType.Blacklist
RayTestParams.FilterDescendantsInstances = {player.Character}
RunService.Heartbeat:Connect(function(dt)
game:GetService("RunService").Heartbeat:Connect(function(dt)
local rayResult = workspace:Raycast(bullet.Position, bulletMoveDirection, RayTestParams)
if rayResult then
print("bruuuhhh")
end
end)
end)