Godot Version
4.5
Question
I’m migrating my 3.5 project, where this working fine. In v4.5, when I try to smoothly rotate the player, looking_at() returns to the root scene origin ( global (0,0,0)) although the vector is not (0,0,0), and I cannot understand why.
My code:
func _physics_process(delta: float) -> void:
bla, bla, bla...
## Game is dual stick. mov_joy is movement direction stick. rot_joy is attack direction stick
mov_joy.x = Input.get_axis("LEFT","RIGHT")
mov_joy.y = Input.get_axis("FORWARD","BACK")
rot_joy.x = Input.get_axis("ui_left","ui_right")
rot_joy.y = Input.get_axis("ui_up","ui_down")
var mirar_target
direction = Vector3.ZERO
rot = Vector3.ZERO
direction = Vector3(mov_joy.x,0,mov_joy.y)
rot = Vector3(rot_joy.x,0,rot_joy.y)
### VIVO
if vida > 0 :
bla, bla, bla...
ESTADOS.RELOADING:
speed = SPEED_IDLE
mirar_target = global_transform.origin + direction.normalized()
velocity = lerp(velocity,direction.normalized() * speed, ACEL* delta)
velocity.x = clamp(velocity.x, -MAX_SPEED, MAX_SPEED)
velocity.z = clamp(velocity.z, -MAX_SPEED, MAX_SPEED)
if not is_on_floor():
velocity += get_gravity() * delta
move_and_slide()
### PROBLEM IS HERE, BUT ONLY IF direction is 0:
if rot.length_squared() > 0 or direction.length_squared() > 0:
var transf = global_transform.looking_at(mirar_target, Vector3.UP)
global_transform = global_transform.interpolate_with(transf, ACEL * delta)
if direction is 0, looking_at gives a transform to the root scene (0,0,0) although mirar_target is NOT 0. As after I interpole player transform with this, player moves to scene origin.
I cannot understand why, and in v3.5, same code works fine.
Any insight?