-
What do you want to achieve? I’m trying to make a part spawn where the player clicks and shortly after, 3 more parts around the part previously spawned.
-
What is the issue? While i managed to make the parts spawn in a circular path, for some reason the direction is wrong.
As you can see from the pics the blue parts are around the purple part, however they spawn on the side. I’m trying to make them spawn vertically, facing the bottom of the purple part, like this (i manually changed the position):
-
What solutions have you tried so far? I tried editing the pivot property, play around with the CFrame but nothing seems to work.
Here is the code:
local Players = game:GetService("Players")
local Shard_Model = game:GetService("ReplicatedStorage"):WaitForChild("Shard")
local Rune_Model = game:GetService("ReplicatedStorage"):WaitForChild("RuneShard")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local TS = game:GetService("TweenService")
local DS = game:GetService("Debris")
local function renderShard(Shard)
local InfoTween = TweenInfo.new(0.15,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local goal = {}
goal.Size = Shard.Size + Vector3.new(0.15, 0.15, 7)
local spawnShard = TS:Create(Shard,InfoTween,goal)
return spawnShard
end
local shards = {}
local numberOfShards = 3
local skillRadius = 10
local function getXAndZPositions(angle,radius)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
local function chargedAttack(player,char,mouse)
local HRP = char:FindFirstChild("HumanoidRootPart")
local RuneShard = Rune_Model:Clone()
local RuneTween = renderShard(RuneShard); RuneShard.Color = Color3.fromRGB(135, 14, 255)
RuneShard.CFrame = CFrame.new(mouse.Position) * CFrame.new(0,10,0)
print(RuneShard:GetPivot())
RuneShard:PivotTo(CFrame.lookAt(RuneShard.Position,mouse.Position))
RuneShard.Anchored = true
RuneShard.CanCollide = true
RuneShard.Parent = workspace
RuneTween:Play()
local fullCircle = 2 * math.pi
for i = 1, numberOfShards do
table.insert(shards, Shard_Model:Clone())
end
for i, part in pairs(shards) do
part.Anchored = true
part.CanCollide = true
part.Parent = workspace
end
for i, part in pairs(shards) do
local angle = i * (fullCircle / #shards)
local x, z = getXAndZPositions(angle,skillRadius)
local position = (RuneShard.CFrame * CFrame.new(x, 5, z)).p
local lookAt = RuneShard.Position--HRP.Position
local newCFrame = CFrame.new(position,lookAt)
part.CFrame = newCFrame
local tween = renderShard(part)
tween:Play()
end
end
If something isn’t clear, please let me know and I’ll try to explain better!