I'm working on a 3D puzzle platformer game where you use gravity to your advantage
and i tried to make the player slowly rotate to an angle with gravity and it only goes about half way but when i set it manually in the editor it goes to the correct angle

func AV_gravity(on : bool):
if on == true:
if Zero_grav != true:
apply_central_force(gravity_dir * gravity_strength)
if int(gravity_dir.x) << 0:
rotation_degrees.z = lerp(rotation_degrees.z,(deg_to_rad(90.0)),0.5)
if int(gravity_dir.x) >> 0:
rotation_degrees.z = lerp(rotation_degrees.z,(deg_to_rad(-90.0)),0.5)
if int(gravity_dir.z) << 0:
rotation_degrees.x = lerp(rotation_degrees.x,(deg_to_rad(90.0)),0.5)
if int(gravity_dir.z) >> 0:
rotation_degrees.x = lerp(rotation_degrees.x,(deg_to_rad(-90.0)),0.5)

  • Toxe replied to this.

    UnaversallyKnown What are these supposed to do?

    if int(gravity_dir.x) << 0:

    Are you sure you want to use << (which is a bit shifting operation) and not just < for a simple comparison?

      Toxe

      if int(gravity_dir.x << 0:

      is suppose to detect the gravity is the negative x direction
      but that seems to work fine though I'll change it because i didn't know you could do <

      turns out
      rotation_degrees.z = lerpf(rotation_degrees.z,-90.0,0.25)
      works i got rid of the deg_to_rad and switch lerp to lerpf
      i dont know what lerpf does but it saved this project though.

      • Toxe replied to this.

        UnaversallyKnown i dont know what lerpf does

        lerpf() explicitly expects float arguments whereas the generic lerp() function takes any Variant values and then tries to make sense of them. It's always best to use the more explicit function versions (the ones ending on "f" or "i" like minf() or mini()).

        UnaversallyKnown but it saved this project though

        It has probably more to do with a mixup between rotation angles in degrees and radians. Where does rotation_degrees come from and are those values in radians or degrees?