Hey guys. I am trying to fix a randomly rotating cube that uses angular velocity and linear velocity. When one person stands on the cube, there is no lag and it rotates perfectly uses a rotation script that changes angular velocity values. However, as soon as two or more people stand on the rotating cube, it starts to lag and freeze. I’ve tried setting the primary part of the cube to a server network owner, but this hasn’t fixed the problem. Any recommendations on what should be done?
Set the network owner of each of the cube’s parts to ‘nil’ (the server).
I used the script below, but the cube still seems to lag when there are two people on it. When it’s just myself on the cube, it works flawlessly. Does the script look alright?
for i, child in pairs(game.Workspace.CurrentMap:GetDescendants()) do
if child:IsA("BasePart") then child:SetNetworkOwner(nil) end
end
You’ll need to perform this inside of an event loop for unanchored parts.
What do you mean by event loop? Forgive my lack of knowledge.
Set the relative to property of the angular velocity to World. Also set the network owner to the most recent player that touched the cube.
The relative for the angular velocity is already set to World. For the network owner, I’ve had most people tell me to set it to the server, but I must be doing it wrong. If only I could find out what an event loop is.
Setting the network owner to server isn’t good because everyone already views the cube’s movements on the server. setting the network owner to a player makes that player the priority and makes the cube smooth for that player (as if the cube is rotating on the client / local space). You can only set the network owner to one player max for each base part.
The problem is since only 1 player can have smooth cube rotation means that it will still lag for other players.
Here’s an article that might help: Physics Best Practices
(Taken from article)
- Use the minimum number of constraints to get the job done. While a door in real life may have three hinges, in Roblox you only need one.
- But don’t be afraid to mix and match! You’ll often want to use more than one constraint to get a certain interaction feeling right. For example combining a Spring with a Prismatic for suspension, a Ball Socket with AngularVelocity for a damped rotation joint, or simply VectorForce and Torque for precise movement control.
- Avoid having misaligned constraints before running your game. You can tell something is misaligned when you see any red bits on the constraint or attachment renders. Misaligned constraints will cause parts to apply forces to snap together on Start, and cause unexpected behavior.
- Avoid large differences in mass between parts connected by a constraint. If you have a very large part (or group of connected parts) that are constrained with some very tiny parts, then you might run into this. You’ll want to increase the small part’s density of its CustomPhysicalMaterial, and decrease the large part’s density, to have the two parts almost equal in mass.
- Setting MaxForce to infinity on a constraint is rarely the best option. Try to find the actual highest force needed to get your desired behavior.
Problem still isn’t solved if anyone has any other ideas.