Hello Developers. My game focuses on a peice of land that each placer has. Each player has their own floating island, generated on join, and removed when players leave. I have gotten it to work with it’s position, It’s all fouced on a center part. However, things get weird when I want to rotate it so each island is facing each other. These parts are in folders, not models. So I have tried many ways to rotate it around a part by 180 degrees, but all have failed. I don’t have a script for rotating because all attempts have failed. Anyone able to help me or link me to resources? Any help is Appreciated!
Thanks for the effort. The issue is there isn’t a ‘primary part’. I am moving each part, rather then models, because there is folders. Also my game isn’t formatted like that (And this is my fault for not explaining this) But hopefully this image makes sense, But that there is no center inbetween islands, just islands have their own center, and in that part is a value in degrees for how many degrees it needs to be rotated
Although I have tried some different things, and ended in something like this…
When you say rotate do you mean as in animation? Or just move it once?
If the former let me know as it’ll require a more indepth solution but since you have a single part, you could just get all the surrounding parts, get its CFrame relative to the central part or centre point, then translate the central part’s CFrame by how ever many degrees, then for every part, translate the relative CFrame back into world coordinates.
It can be pretty performance intensive depending on how many parts you’re looking to translate so I would advise not doing it more than necessary, but it sounds harder than it actually is. Suppose centrePart is the part which you want to rotate parts around, and partsToTranslate is your folder.
local centrePart = workspace.CentrePart
local partsToTranslate = workspace.PartsToTranslate
local centreCFrame = centrePart.CFrame -- just so we don't have to index it through the part every time (it'll save you a bit of time believe it or not because indexing things does still take time)
-- Okay, step one would be to create a table and fill it with the part as the index, and the value as the CFrame relative to the centre part:
local relativeCFrames = {}
for _, part in partsToTranslate:GetDescendants() do
if not part:IsA('BasePart') then
continue
end
relativeCFrames[part] = centreCFrame:ToObjectSpace(part.CFrame)
end
-- now our relativeCFrames table will be populated with a bunch of parts as indices and CFrames as values (so relativeCFrames[part] = someCFrame that is relative to the centre CFrame
-- so now we need to translate our CFrame by however much you want (saw you wanted to do 180deg so we'll do that but you can do any arbitrary translation)
local translatedCFrame = centreFrame * CFrame.Angles(0, math.pi, 0)
-- finally, we translate back to world coordinates relative to translatedCFrame
for _, part in partsToTranslate:GetDescendants() do
if not part:IsA('BasePart') then
continue
end
part.CFrame = translatedCFrame:ToWorldSpace(relativeCFrames[part])
end
And that should give you your expected result.
I mean rotate as just a one time quick rotation, this is a player join event, and I didn’t want anything to cause lag if you were curious. Anyways, Thank you so much! After scaling it to my code it works perfectly, and I would have never found the solution. Again, Thank you so much!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.