You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I have a large model, and I want to rotate it 180 degrees during the gameplay, in a way that it would be good for performance.
What is the issue? Include screenshots / videos if possible!
The issue is that the model is incredibly big and detailed (The model is multiple large and higly detailed rooms) (screenshots included below, remember that I didn’t include every room!). Currently, I’m using the :SetPrimaryPartCFrame() along with a Heartbeat loop, to rotate smoothly. However, this method creates some offsets in many parts within the model, and makes the process laggy, especially on mobile.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked for solutions on DevForum, but I didn’t find anything. Noone seemed to move such big models.
Long story short, I’m trying to achieve the rooms rotating 180 degrees smoothly, so that it won’t hurt performance, and won’t cause offsets withing parts.
I’m aware only of the Welding method, but I’m not sure if It would be good for performance.
If you need any clarification on my problem, feel free to ask!
The issue is lagging and offsets in parts within the model?
you could try to weld the parts that make an offset to those that don’t get an offset
But i prefer using :PivotTo(), its the function to replace the :SetPrimaryPartCFrame() method because its Deprecated,
because :PivotTo() is made for models and it doesn’t need any loop i think.
So try using :PivotTo() for the entire model instead of :SetPrimaryPartCFrame()
Have you tried using :PivotTo()? I think it works pretty well with large models, but honestly I don’t think there is a performant solution to your problem. May I ask what are you trying to achieve with this rotation?
I’m making a game about a shipwreck. Basically the moment where everything rotates 180 degrees, is where the disaster strikes. After that rotation, the model doesn’t suffer any changes in it’s position, and then the main gameplay happens (players escaping the ship).
Basically the whole capsizing thing is the highlight of the game.
Use this for lag reduction if you can Workspace:SetStreamable(true). or look for StreamingEnabled property in workspace
And to change the loading radius do this game.Workspace.StreamingTargetRadius = 500 or also look for the property in the same area.
The Streaming stuff basically stops loading parts outside the localplayer's distance range,
wich would be helpful for your lagging / performance issue.
local RS = game:GetService("RunService")
local cf = model:GetPivot()
local to_cf = cf * CFrame.Angles(0, math.pi, 0)
local time = 0
local time_to = 3
while time < time_to do
time = math.min(time_to, time + RS.PreSimulation:Wait())
model:PivotTo(cf:Lerp(to_cf), time/time_to)
end
If you want to rotate players, it’s new_cf:ToWorldSpace(old_cf:ToObjectSpace(playerCurrentCf)), which is new_cf * old_cf:Inverse() * playerCurrentCf
This player move code is much smoother on the client, just record the old_cf at the end of the connected frame function.
You could also put an invisible - anchored part to the center of the ship, then unanchor and weld the whole ship to this single part. So you only have to tween the part by 180°.
Ahem, so I integrated the :PivotTo() system in my game, and it works generally fine. However. I feel like I should have probably mentioned that when the model starts to rotate, almost all the furniture gets unanchored and starts to slide down the floor (that is the plan). However, when I have furniture unanchored, the model rotates really slow. To the point where the sound effect for the capsize ends before the whole rotation process is completed.
Any way to have the :PivotTo() work fine when there are a lot of unanchored stuff with physics?
local FurnitureFolder = workspace.FurnitureFolder --The folder location
for i, furniture in ipairs(FurnitureFolder:GetDescendants()) do
--gets all of the Descendants inside the folder and runs the code for every part only
--GetDescendants() gets "Everything" inside the folder including parts inside models or other...
if furniture:IsA("BasePart") then-- this is used for only changing the parts, so that it doesn't run for anything else exept parts.
furniture.Anchored = false -- Unanchor the part
end
end