Rotating breaks game, throws error det==0 every frame

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alskdjfhg

No issue translating, but rotating at all breaks the viewport and throws the error “det==0” and “set_axis_angle: The axis Vector3 must be normalized.” The Vector3 I’m trying to rotate it by is normalized, and all of the scales on everything aren’t 0, which I’ve seen has caused the error before.

Can you share your code as well?

DDoop | 2020-07-10 20:27

GitHub - frenchma/Game-stuff

This has all the code in the project

alskdjfhg | 2020-07-10 20:29

What happens when you use rotate() instead of rotate_object_local()?

DDoop | 2020-07-10 20:59

the same thing

alskdjfhg | 2020-07-10 21:08

:bust_in_silhouette: Reply From: klaas

Hi,
a zero vector normalized does not return a proper normalized vector.

Vector3().normalized returns (0,0,0) … not of length 1

When you start your code, spin_inertia is a zero vector.

when your code depents on a proper normalized vector better make your own fail safe function

func normalize( vec:Vector3 ):
    var newVec = vec.normalized()
    if newVec.length() < 1:
        newVec  = Vector3.UP #or whatever is your default
    return newVec

Not tested!

Had the same problem, the above function fixed it

I had:

transform.basis = transform.basis.rotated(Vector3.ZERO, pitch_input * pitch_speed * delta)

changed to:

transform.basis = transform.basis.rotated(normalize(Vector3.ZERO), pitch_input * pitch_speed * delta)

no more errors at runtime, works same as previous line, cheers

SureJungle23247 | 2021-05-15 17:39