So with the following script, i have it set up so i can rotate a sphere around another sphere about the x, y, or z planes:
local Center = script.Parent.Center
local Ball = script.Parent.Part
game:GetService("RunService").Heartbeat:Connect(function()
local yPlane = Vector3.new(math.sin(tick()) * 4, 0, math.cos(tick()) * 4)
local xPlane = Vector3.new(0, math.sin(tick()) * 4, math.cos(tick()) * 4)
local zPlane = Vector3.new(math.sin(tick()) * 4, math.cos(tick()) * 4, 0)
Ball.Position = Center.Position + yPlane
end)
But what if i wanted to rotate the sphere about two or more planes at the same time? simply adding them together doesnt seem to work, and i dont really know how to go about this.
I seemed to have solved it by combining two of the planes (in this case x and y), multiplied the Z component by a square root of two, and then divided the resulting vector by a square root of two, like so:
local Center = script.Parent.Center
local Ball = script.Parent.Part
game:GetService("RunService").Heartbeat:Connect(function()
local yPlane = Vector3.new(math.sin(tick()) * 4, 0, math.cos(tick()) * 4)
local xPlane = Vector3.new(0, math.sin(tick()) * 4, math.cos(tick()) * 4)
local zPlane = Vector3.new(math.sin(tick()) * 4, math.cos(tick()) * 4, 0)
local testPlane = Vector3.new(math.sin(tick()) * 4, math.sin(tick()) * 4, math.cos(tick()) * 4 * math.sqrt(2)) * 1/math.sqrt(2)
Ball.Position = Center.Position + testPlane
end)
Now there is a new problem. What if i want to rotate about both planes, but i want to rotate them independently of each other? (ie. 50 degrees about the x plane and 95 degrees about the y)
i dont think you quite understand the question. In the first example, The same variable (the tick function) was used in all three parameters of the calculation. It was essentially creating a new plane that was offset between the x and y planes. But now i am trying to not combine the two planes, but have them work in unison. I am not trying to make a new plane, but rather have it rotate along the x and y planes independently. For the x and y components, i can just use the sines of the x and y. But what of the Z component? what combination of x and y angles am i supposed to plug in here?
In the first post, you can see two gifs. In the first one, the sphere can be observed rotating about the y axis, and in the second one it is seen rotating about the x axis. What i want to achieve is to have them rotate about both axes independently at the same time.
The problem requires an in depth understanding of trigonometry. I understand that my language may not have been perfect, and i apologize for that; it can be tough for me to explain problems like this one sometimes
He means rotation around two axes. That’s fairly straightforward with CFrames, but I’m not some genius at math. Here’s a crack at it, but it might not be what he wants.
local z, t = math.sin(a2), math.cos(a2)
local x, y = math.sin(a1)*t, math.cos(a1)*t
From here you can specify an origin and a radius to fit your video if you wish. You can swap or negate axes to get different directions of rotation.
You mean like I just did here? Select the text you want to quote and a little button saying Quote will pop up. Just press that.
Or if you want to link to another other post, just press this on the post you want to embed. If you’re on mobile it might be buried behind a menu button in the same location.
The only way to accomplish what you want is by rotating each angle in YXZ order. ball.Position = (CFrame.new(center.Position) * CFrame.fromEulerAnglesYXZ(yPlaneRotation, xPlaneRotation, zPlaneRotation) * CFrame.new(0, 0, -center.Size.Z/2)).Position