Hi, I’m trying to design a “Hyper Drive” effect and have elected to use this style of shape to generate the beams etc. prior to moving to give a somewhat circular illusion around the ships.
I was wondering how I could use Code to generate the expanding circle shape from infront of the ship going outwards as displayed.
Currently my method works using random offsets along the RightVector and UpVector of the Star ship and I wish to change this to the circular effect shown.
I found a snippet of code that works perfectly; however I need to adjust the angles to allow for the circular pattern to be directly infront of the Ship as opposed to on the ground itself -
for i = 0, math.pi*2, math.pi*2/reps do
local a = Middle:clone()
a.Position = orig+Vector3.new(rad*math.sin(i), 0, rad*math.cos(i))
a.CFrame = CFrame.new(a.Position, orig)
a.Anchored = true
a.Parent = workspace
end
EDIT2://
I successfully managed to get it tilted in the right direction - Now it’s a matter of the Orientation:
The centre part is where the Ship will be located and will need to correspond with the orientation? How could I adjust this to allow for the circle to share the same orientation?
All you have to do from here is define a reference point (so the nose of your ship for example) and translate the entire structure to that point.
local origin = ship.Part.CFrame
for i = 0, math.pi*2, math.pi*2/reps do
local a = Middle:clone()
a.Position = Vector3.new(rad*math.sin(i), 0, rad*math.cos(i))
a.CFrame = CFrame.new(a.Position, orig)
a.CFrame = origin.CFrame * a.CFrame
a.Anchored = true
a.Parent = workspace
end
To rotate the structure you can either rotate your reference part or rotate the origin CFrame (by, for example, appending * CFrame.Angles(0, 0, math.pi/2) to the first line.
Another possible way is to construct it into the a new origin and axis like a geometrical plane. You can do this by multiplying the
rad*math.sin(i)
With the UpVector of the ship to obtain the y axis change for that ship.
And
rad*math.cos(i))
With the RightVector to obtain the relative x axis change for that shift. Then you add these two vectors with the ships world position to get the new parts position on a plane defined by the UpVector and RightVector of the ship I believe.
That works fine, Other than the cloned parts not sharing the same Orientation, however -
When I use a.CFrame = CFrame.new(a.Position, Middle.Position)
I get this result where it doesn’t share the same rotations at all:
You need to use both lines, first the CFrame.new call, then origin * a.CFrame, or, simplified to one line (since it originally was just a demonstrative solution):
local origin = ship.Part.CFrame
for i = 0, math.pi*2, math.pi*2/reps do
local a = Middle:clone()
a.CFrame = CFrame.new((origin.CFrame * CFrame.new(rad*math.sin(i), 0, rad*math.cos(i))).Position, Middle.Position)
a.Anchored = true
a.Parent = workspace
end