Rotation Not Working In Game Like it's working in editor
Asked Answered
S

4

0

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)

Septicidal answered 24/1 at 6:11 Comment(0)
V
0

Septicidal 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?

Vanhouten answered 24/1 at 10:47 Comment(0)
S
0

Vanhouten

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 <

Septicidal answered 24/1 at 14:1 Comment(0)
S
0

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.

Septicidal answered 24/1 at 14:31 Comment(0)
V
0

Septicidal 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()).

Septicidal 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?

Vanhouten answered 24/1 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.