Godot Version
4.4.1
Question
Hi, I’m trying to smoothly interpolate my characters rotation to a rotation I construct based on a given direction and the slope/tilt of the ground the character is currently on, however, everytime the final slerp is called godot throws this error, which doesnt crash the game but just doesnt implement any rotation.
I tried calling normalized and orthonormalized on all of the vectors and bases involved but it still throws the same error. I tried rounding the vectors to two decimals as well. Here is the function.
Edit: The error is caused by the final slerp at the end.
func turnCarTowards(target_direction: Vector3, delta) -> void:
var target_basis
#Constructing Desired Rotation from Target Direction and Ground Rotation
if ground_ray.is_colliding():
var new_up = ground_ray.get_collision_normal()
var forward_flat = - flatten(target_direction).normalized
var new_right = new_up.cross(forward_flat).normalized()
var new_forward = new_right.cross(new_up).normalized()
target_basis = Basis(new_right, new_up, -new_forward).orthonormalized()
#This Implements constant turn speed by scaling step
# shouldn't have anything to do with the error
var target_quat = target_basis.get_rotation_quaternion()
var quat = transform.basis.get_rotation_quaternion()
var angle_to_turn = abs(quat.angle_to(target_quat))
angle_to_turn = clampf(angle_to_turn, 0.01, angle_to_turn)
var step_scale = slerp_rotation_breakpoint / angle_to_turn
var step = delta * rotation_speed * step_scale
step = clampf(step, step, 1.0)
transform.basis = transform.basis.slerp(target_basis, step).orthonormalized()
