Currently learning with beams but unsure on how to implement it into my code or on how to even set it up
local Gunpart = script.Parent
local MuzzleVelocity = 710
local bulletPos = Gunpart.Position
local bulletVelocity = Gunpart.CFrame.LookVector*MuzzleVelocity
local RunS = game:GetService("RunService")
local function fireBullet()
local dt = RunS.Stepped:Wait()
local RayStepped
RayStepped = RunS.Stepped:Connect(function()
local intersectionpoint = bulletPos + bulletVelocity/2
local bulletCast = workspace:Raycast(bulletPos, bulletVelocity)
bulletVelocity = bulletVelocity - (Vector3.new(0, workspace.Gravity, 0) * dt)
bulletPos = bulletPos + bulletVelocity * dt
local function tracereffect()
local A0 = Gunpart.TracerA0
local A1 = Gunpart.TracerA1
local tracer = Gunpart.TracerBeam
A0.Position = bulletVelocity
A1.Position = bulletPos
end
if bulletCast then
local Landedpart = Instance.new("Part")
Landedpart.Parent = workspace
Landedpart.Anchored = true
Landedpart.Position = bulletCast.Position
Landedpart.Size = Vector3.new(10, 10, 10)
Landedpart.Material = Enum.Material.Neon
Landedpart.BrickColor = BrickColor.new("Bright red")
RayStepped:Disconnect()
else
bulletPos = bulletPos + bulletVelocity
end
if bulletVelocity.Magnitude >= 750 then
RayStepped:Disconnect()
print("stopped")
end
tracereffect()
end)
end
fireBullet()
Been using this block of code for tracers, with my understanding that every time the raycast updates the position of the attachments also update but I feel like this maybe the wrong approach
local function tracereffect()
local A0 = Gunpart.TracerA0
local A1 = Gunpart.TracerA1
local tracer = Gunpart.TracerBeam
A0.Position = bulletVelocity
A1.Position = bulletPos
end
Srry for bad english, lmk if topic is in wrong place or needs correction
