Pretty self explanatory: I want this part to move in an orbit around this other long part.
I don’t know where to start on doing this as I’m quite bad at math. I’d really appreciate if anyone could give me some guidance.
Ultimately what I’m trying to do is have this shopping cart tilt over when it’s turning as that’s a nice effect. I think if I can figure out how to do the first part I should be able to apply it here.
local origin = game.Workspace.main
local radius = 5
local speed = 1
local angle = 0
while true do
task.wait()
angle += speed * 0.05
local x = math.sin(angle) * radius
local z = math.cos(angle) * radius
script.Parent.Position = origin.Position + Vector3.new(x, 0, z)
end
Honestly I don’t even think this approach is needed.
Why should the cart have to rely on another part to handle its own orientation?
Assuming this is a player controlled cart, you first should check for user input. For simplicity, I’m only going to account for PC players in this example. If the player presses “A”, you should just smoothly tween the model on the desired axis. And the same applies for the “S” key.
Hey, so I think I got what your looking for, adjust the settings a little to your liking, remove the negative to the rotation if you want it to tilt inwards. Anyway, here you go:
local origin = workspace.Origin
local radius = 5
local speed = 1
local angle = 0
local TiltAngle = 8
while task.wait() do
angle += speed * 0.05
local xPos = math.sin(angle) * radius
local zPos = math.cos(angle) * radius
local nextAngle = angle + 0.01
local nextZPos = math.cos(nextAngle) * radius
local nextXPos = math.sin(nextAngle) * radius
local nextPosition = origin.CFrame * Vector3.new(nextXPos, 0, nextZPos)
script.Parent.CFrame = CFrame.lookAt(origin.CFrame * Vector3.new(xPos, 0, zPos), nextPosition)
* CFrame.Angles(0, 0, -math.rad(TiltAngle))
end
I used @neviquatro’s base rotation code, and adjusted it to what you wanted and put in the comments.
task.wait() will wait 1 frame which means the part will rotate depending on the fps rate
which can be fixed by u using a time global like tick or time rather than incrementing angle