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

Why can't I rotate Player via Attitude past 90 degrees?

Asked by 9 years ago

So I have been working with CFrame a bit, just playing around, and I wrote a script so that when W is pressed the character rotates forwards. Everything works without errors, however, when the player has rotated to 90 degrees or-90 degrees, it refuses to rotate farther. I currently have PlatformStand set to true (prevents player from auto-rotating back to original state) and DevComputerMovementMode set to scriptable (so the player doesn't move forward when W is pressed. I also have a BodyForce in the player to cancel out the effects of Roblox gravity. Here is the main part of the script I am having trouble with:

Input.InputBegan:connect(function(InputObject)

    if  InputObject.KeyCode == Enum.KeyCode.W then
        if XRotB == true then --Ignore this statement, it is for later purposes
            XRotB = false
        end
        XRotF = true
        while XRotF == true do
            wait()
            local Matrix = Character.Torso.CFrame
        local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = Matrix:components()
        local Heading = math.atan2(m02, m22)
        local Attitude = math.asin(-m12) - 0.025
        local Bank = math.atan2(m10, m11)
        local PosX = Character.Torso.Position.X
        local PosY = Character.Torso.Position.Y
        local PosZ = Character.Torso.Position.Z

        Character.Torso.CFrame = CFrame.new(PosX, PosY, PosZ) * CFrame.Angles(0, Heading, 0) * CFrame.Angles(Attitude, 0, Bank)
        print(math.deg(Attitude))
        end
        end
end)

Like I said, I am just learning about advanced CFraming so I apologize if it is messy... Again the issue is that the rotation won't pass 90 degrees or-90 degrees, as proven by when I print the math.deg(Attitude). Any suggestions?

0
Never mind.... Basic rules of Trigonometry I neglected to look into.... any value below -1 will produce no value when plugged into the inverse of sine. FireFruit226 35 — 9y

Answer this question