Search code examples
luascriptinggame-developmentroblox

Having an issue with Gyros on roblox


Whenever i use body gyros to make the player look straight up it starts flinging the character, and sometimes just slightly straight up and it still flings the character, i've searched around but couldn't find a solution for my problem, any tips or advice on how i can prevent this issue or an alternative solution?

This is how i make the player look in the direction the velocity is going: bodyGyro.CFrame = CFrame.lookAt(Vector3.new(), bodyVelocity.Velocity.Unit * 2 * rayDirection)

The rayDirection is just either 1 or -1.

i've tried disabling ragdoll on the humanoid but that didn't help.


Solution

  • I see you're using the CFrame.lookAt function, if you read the documentation, you can find out the following:

    Returns a new CFrame with the position of at and facing towards lookAt, optionally specifying the upward direction (up) with a default of (0, 1, 0).

    And if you read a little bit more up:

    At high pitch angles (around 82 degrees), you may experience numerical instability. If this is an issue, or if you require a different "up" vector, use CFrame.fromMatrix() to more accurately construct the CFrame. Additionally, if lookAt is directly above pos (pitch angle of 90 degrees), the "up" vector switches to the X axis.

    This would mean it is expected behavior, as the numerical instability, combined with the velocity settings in your bodygyro, cause this flinging.

    As the documentation describes, you want to look into CFrame.fromMatrix to construct a proper CFrame. If that doesn't work, you also want to check if modifying the up vector manually works.