Hello,
I'm trying to make a spinner which the player stands on to move around the map. I have tried to use BodyGyro and CFrame to do this.
I find that CFrame studders from degree to degree, which doesn't look very aesthetic. This was my attempt at using CFrame to move the part:
1 | local brick = script.Parent |
2 | local a = 0 |
3 | while true do |
4 | wait() |
5 | local a = a + 0.04 |
6 | brick.CFrame = brick.CFrame * CFrame.Angles( 0 , a , 0 ) |
7 | end |
Again, this did work, but it wasn't very smooth.
I couldn't get the BodyGyro attempt to work either. Firstly, because I had to unanchor the block, causing the block to fall out of the map. Secondly, because it just didn't rotate :(
This was my attempt on using BodyGyro to rotate the part:
1 | local brick = script.Parent |
2 | local body = script.Parent:FindFirstChild( "BodyGyro" ) |
3 | local a = body.CFrame.Y |
4 | while true do |
5 | wait() |
6 | local a = a + 1 |
7 | body.CFrame = CFrame.Angles( 0 ,a, 0 ) |
8 | end |
And again, this script didn't work at all :(
I would be grateful if you could help me create this smooth rotating block. Thanks.
you can use TweenService
to tween the part smoothly.
01 | local ts = game:GetService( "TweenService" ) |
02 | local part = script.Parent -- lets say this was the part |
03 |
04 | local info = TweenInfo.new( 5 , Enum.EasingStyle.Linear, Enum.EasingDirection.Out,- 1 ) |
05 | local properties = { CFrame = script.Parent.CFrame * CFrame.Angles( 0 ,math.rad( 180 ), 0 ) } |
06 |
07 | local tween = ts:Create(script.Parent,info,properties) |
08 |
09 | tween:Play() -- plays the tween |
10 |
11 | --[[ |
12 | tween:Cancel() -- stops the tween |
13 | tween.Completed -- when the tween finishes |
14 | --]] |
TweenInfo.new()
actually takes 6 parameters, though you dont need to use all of them. the first parameter is how long should the tween go to the objective, for this it would take 5 seconds to rotate 180 degrees. Enum.EasingStyle.Linear
is just a easing style, you can choose other easing styles too. the rest you can find out here TweenInfo.new().