I’m trying to make an effect for a game where partially through an event, the player starts orbiting a part, kind of like how GLaDOS drags the player across the room in Portal: Prelude, yet I’m not sure of the best way to do it.
1 Like
Can you provide more details?
What do you mean by orbiting?
By orbiting I mean; the player would start floating / moving around the part.
Hello Jayden heres a quick orbit script i made some time ago hopefully this helps!
local Part = workspace.Part -- The part
local Player = game.Players.LocalPlayer -- The player that orbits the part
if not Player and Part then return end
local Character = Player.Character
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local Distance = 10 -- Edit the distance that the player orbits around the Part
if Character and Part then
local SineX, SineZ = 0, math.pi / 2
game:GetService('RunService').Stepped:Connect(function()
SineX, SineZ = SineX + 0.05, SineZ + 0.05
local SinX, SinZ = math.sin(SineX), math.sin(SineZ)
if HumanoidRootPart and Character then
HumanoidRootPart.Velocity = Vector3.new(0, 0, 0)
HumanoidRootPart.CFrame = CFrame.new(SinX * Distance, 0, SinZ * Distance) *
(HumanoidRootPart.CFrame - HumanoidRootPart.CFrame.p) +
Part.CFrame.p
end
end)
end
1 Like
It works rather well, but a quick question, how would I make the player take damage when they collide with a part while spinning…?
i’m guessing something like this
local Part = workspace.Part -- The part
local Player = game.Players.LocalPlayer -- The player that orbits the part
if not Player and Part then return end
local Character = Player.Character
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local Distance = 10 -- Edit the distance that the player orbits around the Part
if Character and Part then
local SineX, SineZ = 0, math.pi / 2
game:GetService('RunService').Stepped:Connect(function()
spawn(function()
local Parts = workspace:GetPartBoundsInRadius(HumanoidRootPart.Position, 1)
for _, Part1 in next, Parts do
if Part1 ~= Part and Part1.Parent ~= Character and Part1.Parent.Parent ~= Character then
print(Part1.Name)
Character.Humanoid.Health = Character.Humanoid.Health - 0.3 -- Because of the Stepped loop keep the health taken away low
end
end
end)
SineX, SineZ = SineX + 0.05, SineZ + 0.05
local SinX, SinZ = math.sin(SineX), math.sin(SineZ)
if HumanoidRootPart and Character then
HumanoidRootPart.Velocity = Vector3.new(0, 0, 0)
HumanoidRootPart.CFrame = CFrame.new(SinX * Distance, 0, SinZ * Distance) *
(HumanoidRootPart.CFrame - HumanoidRootPart.CFrame.p) +
Part.CFrame.p
end
end)
end
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.