I’m having issues, where once my part goes through a building, it goes to point 0, before starting it’s orbit, which just looks really off. Idea is, it should fly into building and then start to orbit around it, all smooth the whole time.
So it goes through the building, and instead of starting the orbit at the end, it goes back through the building and starts orbit there
local Rotation = 0
while true do
Rotation += task.wait() * ROTATION_SPEED
part.RootPart.AlignPosition.RigidityEnabled = true
part.RootPart.AlignOrientation.RigidityEnabled = true
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
part.RootPart.AlignPosition.Position = OrbitCFrame.Position
part.RootPart.AlignOrientation.CFrame = CFrame.lookAt(
part.RootPart.Position,
building:GetPivot().Position
)
end
1 Like
Would you not be able to just change this:
local Rotation = 0
to something like
local Rotation = 87 --Wherever you want it to start
1 Like
Sorry, I posted the question too early I edited with a bit more info + vid. Problem is, idk how to calculate the rotation value based on where to start
1 Like
I think we may need a bit more of the code preceding the provided bit (so that we can see the code that initially changes it’s position
1 Like
I use a bit of wacky stuff, but
local _, Size = building:GetBoundingBox()
local Goal = part:GetPivot().Position + Vector3.new(0, Size.Y, 0) + (part:GetPivot().LookVector * 25)
part.RootPart.AlignOrientation.CFrame *= CFrame.Angles(0, math.rad(180), 0)
-- Continue through building and up
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = Goal
}
)
Tween:Play()
Tween.Completed:Wait()
local Rotation = 0
-- Get starting position for orbit
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
local BezierCurve = Bezier.new(
part.RootPart.Position,
part.RootPart.Position + (part:GetPivot().LookVector * 5),
OrbitCFrame.Position
)
for i = 1, 4 do
local Percent = (i * 25) / 100
local NewCFrame = CFrame.new(BezierCurve:Get(Percent))
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = NewCFrame.Position
}
)
Tween:Play()
Tween.Completed:Wait()
end
task.wait(0.1)
-- while loop
The bezier code just moves the position along a bezier curve. The first tween occurs after the part has gone through the building. It’s supposed to move up a tad, then the bezier part is supposed to tween it towards the starting orbit point,and then the orbit code in the while is what keeps it rotating.
1 Like
If you remove the bezier curve bit, you may be able to use math.acos()
or math.asin()
to determine which rotation it should start at. Gimme a moment to figure out the math side of it
1 Like
local function CalcRotation = (
local CalcRotPos = Part.Position - building:GetPivot().Position --Change the part to the red cube
local X = CalcRotPos.X
local Z = CalcRotPos.Z
return math.atan(X/Z)
)
local Rotation = CalcRotation
1 Like
Unsure if I did right, but looks really off, like it just jumps
And even if I do a wait, it still moves it to the 0 point, then orbits
1 Like
What is the current script looking like?
1 Like
I changed it from calculating the parts position to the goal, as since I’m using AlignPosition, there’s no way to get if it’s actually made its way to the goal, so figured I’d do from the goal position. But it resulted in the same thing I sent in the gif
Seems to work ok on some angles, as in it’ll print different rotation, and move to somewhat correct spot, but it’s not perfect
local function Orbit(building)
local _, Size = building:GetBoundingBox()
local Goal = part:GetPivot().Position + Vector3.new(0, Size.Y, 0) + (part:GetPivot().LookVector * 25)
part.RootPart.AlignOrientation.CFrame *= CFrame.Angles(0, math.rad(180), 0)
-- Continue through building and up
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = Goal
}
)
Tween:Play()
Tween.Completed:Wait()
local Rotation = CalcRotation(Goal, building)
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
print(Rotation)
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = OrbitCFrame.Position
}
)
Tween:Play()
Tween.Completed:Wait()
task.wait(1)
while true do
Rotation += task.wait() * ROTATION_SPEED
part.RootPart.AlignPosition.RigidityEnabled = true
part.RootPart.AlignOrientation.RigidityEnabled = true
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
part.RootPart.AlignPosition.Position = OrbitCFrame.Position
part.RootPart.AlignOrientation.CFrame = CFrame.lookAt(
part.RootPart.Position,
building:GetPivot().Position
)
end
end
The CalcRotation thing doesn’t actually take any parameters!
It could also just be moved to the main script:
local function Orbit(building)
local _, Size = building:GetBoundingBox()
local Goal = part:GetPivot().Position + Vector3.new(0, Size.Y, 0) + (part:GetPivot().LookVector * 25)
part.RootPart.AlignOrientation.CFrame *= CFrame.Angles(0, math.rad(180), 0)
-- Continue through building and up
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = Goal
}
)
Tween:Play()
Tween.Completed:Wait()
local CalcRotPos = part.RootPart.AlignPosition.Position - building:GetPivot().Position --Change the part to the red cube
local X = CalcRotPos.X
local Z = CalcRotPos.Z
local rotation = math.atan(X/Z)
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
print(Rotation)
local Tween = TweenService:Create(
part.RootPart.AlignPosition,
TweenInfo.new(0.25),
{
Position = OrbitCFrame.Position
}
)
Tween:Play()
Tween.Completed:Wait()
task.wait(1)
while true do
Rotation += task.wait() * ROTATION_SPEED
part.RootPart.AlignPosition.RigidityEnabled = true
part.RootPart.AlignOrientation.RigidityEnabled = true
local OrbitCFrame = CFrame.new(
math.sin(Rotation) * RADIUS,
0,
math.cos(Rotation) * RADIUS
) + building:GetPivot().Position + Vector3.new(0, Size.Y / 2, 0)
part.RootPart.AlignPosition.Position = OrbitCFrame.Position
part.RootPart.AlignOrientation.CFrame = CFrame.lookAt(
part.RootPart.Position,
building:GetPivot().Position
)
end
end
Still same result of reverting back to 0 works on some, acts off on others
Might be to do with some negative things. Ill have a look in a bit
If all fails, you could make a dummyObject, that goes to the building way faster, and send the realObject to it’s CFrame after a set amount of time.