The script does the following:
We start at 0 degrees rotation (i.e: character's y-axis rotation is at 0 at the beginning)
Player on mobile device
Player dragging their finger (touch) to the right
While player is doing that, add 1 degree rotations as long as player's character's y rotation is not >= 180 degrees
Scroll down to [HERE] to see the script in question. Also, all scripts can be tested in studio (they are local scripts). Can I get any input as to what's happening here?
This is what a 180 degree rotation looks like in a test:
https://i.imgur.com/44LTv75.png
This is what that script looks like:
wait(.5)
local userInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
localPlayer.Character.Humanoid.WalkSpeed = 0
--// START:
wait(10)
localPlayer.Character:SetPrimaryPartCFrame(localPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(180), 0))
print("180 degrees rotation applied.")
[HERE] Now this is the actual script that leads to a similar visual effect relatively, but why??? It should go to 180 degrees and then not be able to rotate anymore.
https://i.imgur.com/MlJC71x.png
Local script:
wait(.5)
local userInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
localPlayer.Character.Humanoid.WalkSpeed = 0
--// START:
local touching = false
userInputService.TouchStarted:Connect(function(touch)
touching = true
end)
userInputService.TouchEnded:Connect(function(touch)
touching = false
end)
local yRotation = 0
userInputService.TouchMoved:Connect(function(touch)
local originalXPos = touch.Position.X - touch.Delta.X
local newXPos = touch.Position.X
if (touching) then
if (newXPos > originalXPos) then -- If we're dragging our touch gesture to the right, do this:
if (yRotation < 180) then -- If we're not at 180 degrees yet, allow the rotations to keep incrementing.
localPlayer.Character:SetPrimaryPartCFrame(localPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(yRotation), 0))
yRotation = yRotation + 1 -- Increment rotation by 1 degree.
print(yRotation) -- Output.
end
else
-- Just do nothing if we're dragging to the left.
end
end
end)

1 comment
Clear and concise. Thank you so much!