You can write your topic however you want, but you need to answer these questions:
-
I want to achieve bullet tracers that tween based on distance
-
tracers going in wonky directions even though the module puts At1 at the result position and at0 at the origin
-
swapping values and whatnot
Module:
local tweenservice = game:GetService("TweenService")
local defaultsettings = {
TextureSpeed = 0;
TextureLength = 1;
Texture = "rbxassetid://10822615820";
Color = ColorSequence.new(Color3.fromRGB(255, 170, 0));
Width0 = 0.4;
Width1 = 0.4;
Transparency = NumberSequence.new(0);
LightEmission = 0;
FaceCamera = true;
}
return function(Source : Vector3 , Point : Vector3, Settings)
local direction = (Point - Source).Unit
local distance = (Point - Source).Magnitude
local CBullet = Instance.new("Part")
CBullet.Anchored = true
CBullet.CanCollide = false
CBullet.CanQuery = false
CBullet.Size = Vector3.new(.05,.05,.05)
CBullet.Transparency = 1
CBullet.Parent = workspace.Debris.Tracers
CBullet.CFrame = CFrame.lookAt(Source, Source + Point)
local At0 = Instance.new("Attachment")
At0.Position = Vector3.new(0,0,0)
At0.Visible = true
At0.Parent = CBullet
local At1 = Instance.new("Attachment")
At1.WorldPosition = Point
At1.Visible = true
At1.Parent = CBullet
local beam = Instance.new("Beam")
for property, value in pairs(defaultsettings) do
beam[property] = value
end
if Settings then
for property, value in pairs(Settings) do
beam[property] = value
end
end
beam.Attachment0 = At0
beam.Attachment1 = At1
beam.Parent = CBullet
task.spawn(function()
task.wait()
local track = tweenservice:Create(At0, TweenInfo.new(0.2 * (distance / 25), Enum.EasingStyle.Linear), {Position = At1.Position})
track:Play()
track.Completed:Wait()
--CBullet:Destroy()
end)
end
code in the gun:
for i = 1, bulletcount do
local origin = script.Parent.Handle.Muzzle.WorldPosition
local direction = (mousepos - origin).Unit
local directionCF = CFrame.new(Vector3.new(), direction)
local spreadDirection = CFrame.fromOrientation(0, 0, math.random(0, math.pi * 2))
local spreadAngle = CFrame.fromOrientation(math.rad(math.random(minspread, maxspread)), 0, 0)
local direction = (directionCF * spreadDirection * spreadAngle).LookVector * distance
local raycastresult = workspace:Raycast(origin, direction, params)
if raycastresult then
local result = raycastresult.Instance
local position = raycastresult.Position
local normal = raycastresult.Normal
local character = result:FindFirstAncestorOfClass("Model") or result.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
print(origin)
print(raycastresult.Position)
print(raycastresult.Distance)
module(origin, position, {
Color = ColorSequence.new(Color3.new(1, 0.666667, 0));
Texture = "rbxassetid://4029159704";
Transparency = NumberSequence.new(0);
Brightness = 1;
LightEmission = 1;
LightInfluence = 0;
Width0 = 0.5;
Width1 = 0.5;
TextureSpeed = 0;
TextureLength = 1;
FaceCamera = true;
})
--and so on
green dots = at1
mouse was at same position when shot, bullet holes show at1s preferred position