Update looking_at transform on specific axis before applying it

Godot Version

Godot 4.6

Question

I am using looking_at to turn cards toward the camera. The code is really simple :

var cur_scale = scale
		
var transform_card = global_transform.looking_at(
		lookat.global_position,
		Vector3.UP,
		true)
		
global_transform = global_transform.interpolate_with(transform_card, delta * MOVE_SPEED);
		
scale = cur_scale

Now this does exactly what it should but it is a bit too correct for the cards to feel like they are handled like you would in real life.

I need to soften the rotation (have a certain % less rotation) for the Z and Y axis.
Of course the current transform is done in global and I need to have it in local space so that I can easily touch up the Z and Y rotation.

How can I : Prepare the global_transform (simply with looking_at), convert it into a local transform and then decompose the transform so I can modify the angle before applying it ?

Is that a terrible why to handle it ?

I could write myself an updated looking_at function, would not be hard to do so but why not use what the engine gives me ?

You can use Node3D::rotate_object_local() to rotate a bit around wanted local axes after you’ve done look at.

But if I do a global_transform and the line after a local one, it will override the global entirely right ?

First do the lookat operation which will orient the object exactly, and then nudge that orientation around the local axes.

I was for some reason thinking that the local rotation would override the global one if done one after another.
My bad.

Thank you

1 Like