I’m trying to limit the max rotation speed of a cube. Players need to survive on the cube for a limited time, but if unanchored parts on the cube weight too much, the cube starts to spin very fast, which is bad since the players cannot survive on a cube like that. Video of gameplay below.
The way the cube is built is all the parts are welded together, and in the middle there is a core. That core is attached with a UniversalConstraint to an anchored part.
This is the code that I’ve tried using, it works when there isn’t that many unanchored parts, but it fails if there is too much pressure and the cube starts to spin really fast. You can see the sudden speed change when all the parts fell off.
local MAX_SPEED = 0.1 --This number seems to work good for a max speed
RService.Stepped:Connect(function()
local AngVel = module.Core.AssemblyAngularVelocity --gets the speed of the core
local RotSpeed = math.sqrt(AngVel.X^2+AngVel.Y^2+AngVel.Z^2) --Pythagoras' theorem to get the speed but in a single float
if RotSpeed > MAX_SPEED then -- Sets the Rotation speed if too high.
module.Core.AssemblyAngularVelocity = AngVel / (RotSpeed / MAX_SPEED)
end
end)
I’ve looked for a solution here on the dev forum, but did not find any.