look_at functions of Node3D doesn't work the way I expect it to
Asked Answered
I

1

0

I have next script:

extends CharacterBody3D

func _ready():
	pass
	
func _process(delta):
	if Input.is_action_just_pressed("ui_end"):
		var from = global_transform.origin + (-global_transform.basis.z)
		var to = global_transform.origin + global_transform.basis.z
		print("from= ", global_transform.origin, " + ", (-global_transform.basis.z), " = ", from)
		print("to= ", global_transform.origin, " + ", (global_transform.basis.z), " = ", to)
		print("Conc: from ", from, " to ", to)
		var progress = from.lerp(to, delta * 2)
		print("Progress ", progress)
		look_at(progress, global_transform.basis.y)
		print("Rezult ", global_transform.origin + (-global_transform.basis.z))

And this is my console output:

from= (0, 0, 0) + (0, 0, -1) = (0, 0, -1)
to= (0, 0, 0) + (0, 0, 1) = (0, 0, 1)
Conc: from (0, 0, -1) to (0, 0, 1)
Progress (0, 0, -0.933333)
Rezult (0, 0, -1)

As you se rotation not changed after look_at call. But if lerp weight set to 1 CharacterBody3D rotated well and complete to other direction
So there is some screenshots of A - scene in editor, B - with lerp weight = 0.079325, C - with lerp weight = 1

Inbreeding answered 9/2 at 10:30 Comment(0)
I
0

So no one explanation found

I deside to use following script insted listed one:

extends CharacterBody3D

func _ready():
	pass
	
func _process(delta):
	if Input.is_action_just_pressed("ui_end"):
		var from = -global_transform.basis.z
		var to = global_transform.basis.z
		global_transform.basis = global_transform.basis.rotated(global_transform.basis.y, from.signed_angle_to(to, global_transform.basis.y) * 2 * delta)

Seems it's some issue with look_at function Maybe need to open issue?

Inbreeding answered 10/2 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.