Orbiting a model around a fixed object

Hello.

I am trying to orbit a train in a circular motion around a fixed brick. I have tried to implement solutions I have found around the forums for my problem but i’m not getting the results I need. I am still new to cFrames. I understand the fundamentals of cFrames like how they matrices and the functions you can use to manipulate them, I just cant wrap my head around this problem for some reason.

My code is below. When ran, the object does not rotate, it only rotates about its own axis in place, instead of rotating around the axis of the object. the gif shows whats happens:

https://gyazo.com/8bb49e6a0b976fffd0284de06c2b6ace

local playhouse = game.Workspace:WaitForChild('PlayHouse')
local origin = playhouse.origin
local train = script.Parent

i = 0
while true do
	train.CFrame = CFrame.new(origin.Position) * CFrame.new(0,0,20) * CFrame.Angles(0,i,0)
	i = i+ math.rad(5)
	wait()
end
1 Like

So, i think you can insert a humanoid in the train and invisible parts in the trails, and may work like this:
target1; target;2 target3;… when the train touch the target1, automatically it new target is changed to target2.

SORRY FOR THE RIDICULOUS BAD ENGLISH AND GRAMMAR I DO NOT SPEK ENG VERY WELL but you may understand

infinito loopa may not work cuz is the worst idea i had in my entire life

I might try this but i fear it might end up looking choppy.

1 Like

So, if isnt strange but, no one replied to my post: HELP please! this script isn't working

You have to rotate, then translate:

train.CFrame = CFrame.new(origin.Position) * CFrame.Angles(0, i, 0) * CFrame.new(0,0,20) 
3 Likes

i think you must be experienced-programmer, so, can you please reply my post? no one replied to my post: ServerScript not working

Thanks so much dude. I’m glad it was something this simple.

1 Like