xyz Thank you i learn so much by looking this, i try to understand, correct me if I'm wrong.
So first you declared the variable onready to avoid an error on the wanted basis:
@onready var wanted_basis: Basis = global_transform.basis
Then you created the basis (wanted basis) using for waned_basis.x the mathematical production cross:
if input.length_squared() > 0:
# contruct target orientation basis for player
wanted_basis.z = (input.x * right + input.y * front)
wanted_basis.y = Vector3.UP
wanted_basis.x = wanted_basis.y.cross(wanted_basis.z)
Here you normalized the bases on an orthogonal model
wanted_basis = wanted_basis.orthonormalized()
Finally, you applied the transformation to the basis to orient the direction of the mesh.
# interpolate towards wated basis
global_transform.basis = global_transform.basis.slerp(wanted_basis, 10 * delta)
It works, more or less, I think there is still a problem of fluidity but I do not think it concerns this transformation but the orientation of the camera and the application of direction.
It seems to move a horse, and the problem I think is because the application of direction by camera:
func _input(event):
if event is InputEventKey:
if event.is_pressed() and not event.is_echo():
var b = $"../cam_placer".global_transform.basis
right = b.x.normalized()
front = Vector3(b.z.x, 0.0, b.z.z).normalized()
This part of code I think needs to work in physics process delta but without interfering with the basis of the model.
At this point am I forced to move the camera to another scene to achieve this result?
Can applied mathematics create other magic to this model?
For example, is it possible to lock the basis (after smooth rotation), on the respective x/z angles? (0°,45°,90°,135°,180°,240°,270°,315°)
So that there are not too many inaccuracies the movement\camera direction on movement?
Sorry, I seem to have opened a pandora's box and perhaps the result I am looking for is unrealistic.
It's actually fun!