So I’ve got a Godot 4.5 script where I’m trying to move something off-center in local space depending on the angle at which a RayCast3D collides with the walls. To do this, I’ve converted Vector3s into Vector2s to use the angle_to() function, since I couldn’t figure out signed_angle_to(). Vector math is not my strong suit.
var forward_direction: Vector3 = camera.global_position.direction_to(get_collision_point())
var forward_x = Vector2(forward_direction.x, forward_direction.z)
var forward_y = Vector2(forward_direction.y, forward_direction.z)
var wall_angle_x = Vector2(get_collision_normal().x, get_collision_normal().z)
var wall_angle_y = Vector2(-get_collision_normal().y, get_collision_normal().z)
sphere.position.x = lerp(sphere.position.x, forward_x.angle_to(wall_angle_y), 1.0 * delta)
sphere.position.y = lerp(sphere.position.x, forward_y.angle_to(wall_angle_x), 1.0 * delta)
sphere.position.x = clamp(sphere.position.x, -0.25, 0.25)
sphere.position.y = clamp(sphere.position.y, -0.25, 0.25)
this seems to be working, except that when I’m facing the positive x direction, the sphere moves in the opposite direction it’s supposed to, going left when it’s supposed to go right and vice-versa; I assume there’s a similar direction I could face along the y axis that would cause it to glitch out in the y direction as well, but I’ve not noticed this, possibly because of clamped camera rotation.
I tried changing lerp() to lerp_angle() but with no success (I figured that probably wouldn’t work anyway since it was controlling linear motion, not angular). Any help would be greatly appreciated, I’ve been pulling my hair out over this for days!
