Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Random BodyGyro twitching?

Asked by
funyun 958 Moderation Voter
8 years ago

I'm trying to create a local script for flying, and I'm using a BodyGyro to bend the character forward. This makes the character twitch, and I have no idea why.

player = game.Players.LocalPlayer
repeat wait() until player.Character
character = player.Character
torso = character:WaitForChild("Torso")
humanoid = character:WaitForChild("Humanoid")

UIS = game:GetService("UserInputService")

space_presses = 0
press1 = 0
press2 = 0
flying = false
w_down = false

bpos = Instance.new("BodyPosition")
bpos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

bgyro = Instance.new("BodyGyro") 
bgyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space then
        space_presses = math.min(space_presses + 1, 2)
        if space_presses == 1 then
            press1 = tick()
        elseif space_presses == 2 then
            press2 = tick()
            if press2 - press1 > .3 then
                space_presses = 1
                press1 = tick()
            else
                space_presses = 0
                flying = not flying
                if flying then --When you double jump
                    bpos.Position = torso.Position
                    bpos.Parent = torso --Start flying
                else --When you do another double jump
                    bpos.Parent = nil --Stop flying
                    w_down = false
                end
            end
        end
    elseif input.KeyCode == Enum.KeyCode.W then --When you press W
        w_down = true
        bgyro.Parent = torso
        while w_down and wait() do --And you hold it
            bpos.Position = torso.Position + workspace.Camera.CFrame.lookVector * 10 --Move forward
            bgyro.CFrame = CFrame.new(torso.Position, torso.Position + workspace.CurrentCamera.CFrame.lookVector * 10) * CFrame.Angles(-math.pi/2, 0, 0) --And bend forward 90 degrees
        end
    end
end)

UIS.InputEnded:connect(function(input)
    if input == Enum.KeyCode.W then --When you let go of W
        w_down = false --Break the loop
    end
end)

1 answer

Log in to vote
1
Answered by 8 years ago

It's because of the ridiculous strength of the default ROBLOX player flipping upright.

Set the humanoid of the relevant player to be in PlatformStand while 'flying.'

Ad

Answer this question