I learning Roblox Studio a few days, and I am creating another Obby (I have not found a better way to study the features of the Studio and Lua) and it is not clear to me where the physics goes on the rotating parts.
When I make a part in the form of a connection and a loop with a motor, the player can move along with the rotation of the part.
But when I create a simple Rotator script instead, the part rotates under the player’s feet and doesn’t move it.
Rotator Script
local part = script.Parent
local function randomBetween(min, max)
local RND = Random.new()
return RND:NextInteger(min, max)
end
-- начальный случайный поворот
local initialAngle = math.rad(randomBetween(0,360))
part.CFrame *= CFrame.Angles(0, initialAngle, 0)
while wait(0.01) do
part.CFrame *= CFrame.Angles(0, 0.01, 0)
end
I suspect this is due to the Anchored property. But I don’t know what to change in the script - so that the detail doesn’t slip under the character’s feet.
I believe this is because you’re rotating the part with CFrame. In order to make the player move along with, I believe you have to turn it using roblox physics like a motor or something.
The whole point of using a script instead of a motor is simplicity. I just make a part, copy the rotator script into it, and see the result. It’s faster than making a motor. Therefore, I was hoping that you can simply enable some kind of property that will make the player move along with the part.
By iterating over the properties of the part, I found RotVelocity property.
Rotator Script (New Version)
local part = script.Parent
local function randomBetween(min, max)
local RND = Random.new()
return RND:NextInteger(min, max)
end
local initialAngle = math.rad(randomBetween(0,360))
part.CFrame *= CFrame.Angles(0, initialAngle, 0)
part.RotVelocity = Vector3.new(0, 0.3, 0)
while wait(0.01) do
part.CFrame *= CFrame.Angles(0, 0.01, 0)
end
This makes the character move by part as I wanted. But perhaps there is a more elegant way than getting the angular velocity (0.3 in my case) to the right value.
your method may work, but when you play in an actual online mode, you will notice that the part doesn’t rotate smoothly, also it may adding an extra work for scripts if you have multiple of these.
Instead for going easy, I’d rather find some optimization that was already made specifically for it
Umm.
Make an Anchored Part, add another spinning arm Part that’s Unanchored. Connect the two with the Constraints tool ‘Motor’ and make sure the Attachments in each Part are at the same location. Select both Parts and Group them into a Model. Set the Motor Properties to spin the arm at the speed you want.
When you need another spinning arm select the Model and Ctrl-D copy it then move it where you want it and change the Motor Properties as you’d like. Easy peasy lemon squeezy!