I’m trying to create a tool when you activate it, the player throws spikes onto the floor infront of them. However, I would like those spikes to fan out infront of him like so:
This can be done by add a RightVector, LeftVector, and/or LookVector on the parts velocity to create a spread
local FlipFlop = 0
for i = 1, 12 do -- loop for the projectiles, so if you want 12 projectiles
local Spikes = script.Spikes:Clone()
local ShootingRight = Character.HumanoidRootPart.CFrame.RightVector * 25 + Character.HumanoidRootPart.CFrame.LookVector * 50
local ShootingLeft = Character.HumanoidRootPart.CFrame.RightVector * -25 + Character.HumanoidRootPart.CFrame.LookVector * 50
local ShootingStraight = Character.HumanoidRootPart.CFrame.LookVector * 50
FlipFlop += 1
-- Spike code
-- Velocity Set
if FlipFlop == 1 then
for i = 1, 50 -- Change this number for how long you want them not to fall do -- Makes it so velocity will stay consistent
Spike.AssemblyLinearVelocity = ShootingRight
task.wait(0.02)
end
elseif FlipFlop == 2 then
for i = 1, 50 -- Change this number for how long you want them not to fall do -- Makes it so velocity will stay consistent
Spike.AssemblyLinearVelocity = ShootingLeft
task.wait(0.02)
end
elseif FlipFlop == 3 then
FlipFlop = 0
for i = 1, 50 -- Change this number for how long you want them not to fall do -- Makes it so velocity will stay consistent
Spike.AssemblyLinearVelocity = ShootingStraight
task.wait(0.02)
end
end
end
(Sorry it looks kinda messy, I wrote the code on the forums)
So what the code above does is it gets where the Character is facing by getting where the humanoidrootpart is facing and then the number it get times by is how many studs ahead from the lookvector
So the code above basiaclly says 100 studs from where the character is looking
if you put that on a parts velocity, it will launch it from where the character is looking at a speed of 100 studs per second, and the same goes for the rightvector. You can get the leftvector by just getting the opposite of the rightvector by making the number a negative.
When you add the rightvector and lookvector, it creates a diagonal velocity which creates a spread.
If you wanted just a random spread you can ignore the flipflop and
for i = 1, 12 do -- loop for the projectiles, so if you want 12 projectiles
local Spikes = script.Spikes:Clone()
local ShootingRandom = Character.HumanoidRootPart.CFrame.RightVector * math.random(-50,50) + Character.HumanoidRootPart.CFrame.LookVector * 50
-- Spike code
-- Velocity Set
for i = 1, 50 -- Change this number for how long you want them not to fall do -- Makes it so velocity will stay consistent
Spike.AssemblyLinearVelocity = ShootingRandon
task.wait(0.02)
end
end
end