Basically, I’m trying to make a part orbit a rectangle, However I do not want the orbit to be in a circular motion, I want the part to orbit around the rectangle in a way where it will orbit rectangularly, if that makes any sense. For example:
If the part were to orbit around a sphere, the part would orbit in a circular motion.
If the part were to orbit around a long rectangle, the part will orbit in a long rectangular motion to match the orbit shape.
Something to note is that I cannot use CFrame.Lookat as the orbitting part is supposed to be looking at something other than the part it’s orbitting.
it orbits fine on the Z axis, however on the X axis it doesn’t seem to work, I’ve tried making it work with the X axis by filling out the X axis on the CFrame.new, however it just doesnt orbit the way I want it to.
If anybody can help, all would be greatfully appreciated.
Orbitting in a rectangular motion around the rectangle is what I want for a better understanding (sorry if it sounded complicated and confusing, hopefully this clears it up)
What I don’t want: (orbitting around a rectangular object in a circular motion)
Not a full solution, but one way to think about solving this, is by writing some code to make your blue part follow a custom path. And then that path could be setup in the shape of a rectangle.
The only thing is, you probably want the blue part to turn smoothly around the corners, so you’d need to also have some code to handle moving the part along a Spline. But rest assured, the math behind a spine isn’t super complicated. The math can somtimes look intimidating, but there is some good videos on YouTube about programming splines.
So you’d need to have some code for making a part move along a path, and that path would essentially be a list of straight line segments and splines. And you would essentially be interpolating through the entire path.
This is if you want to be like an animation, of course.
Lastly, you probably want to have the path be auto generated, if you change the size of the part.
So you’d have a seperate script that uses your path creation system. And you’d pick points on the surface of the part, and extend them outwards to create a perimeter around the part.
So you want it to orbit in an ellipse, rather than a circle?
You can do something like this
local angle = 0 --change this every frame
-- run this every frame while increasing angle
local pos = v.Position + Vector3.new(
math.cos(angle) * (v.Size.X + orbitpart.Size.X) / math.sqrt(2)
0,
-math.sin(angle) * (v.Size.Z + orbitpart.Size.Z) / math.sqrt(2)
)
orbitpart.CFrame = CFrame.lookAt(pos, target.Position)
Basically cos(a), sin(a) gives you a point on a circle. You can multiply either component to change into an ellipse.
The sqrt(2) division comes from this stackoverflow post and just lets you figure out how big the ellipse needs to be to contain a rectangle:
@Andrew900460 has good input if you want your orbit to intelligently follow the contours of any arbitrary part shape. I assume here an ellipse is good enough for you.