Hello there
I'm trying to rotate my character on y axis as soon it reaches a maximum angle (120 degrees, PI/3) of it front view. Less than that, it just rotate some bones with IK (already working). So let me show my code a little:
func transformRotate():
#getting directions:
var cameraDirection = camera.get_global_transform().basis[2]
var playerDirection = self.get_global_transform().basis[2]
#get the angle between player and camera:
var angleRad = acos(Vector2(cameraDirection.x, cameraDirection.z).dot(Vector2(playerDirection.x, playerDirection.y)))
#checking if angle is greater than specified:
if (angleRad > PI/3):
#rotating the character (this is where it mess)
self.rotation.y = lerp_angle(self.get_rotation().y, angleRad - PI/3, 1)
#applying IK:
else:
IKTarget.set_rotation(Vector3(-camera.get_rotation().x+90, camera.get_rotation().y+135, 0))
With angle_lerp weight 1, it rotates little after passing maximum angle, increasing weight make it spin (this mess it all, as the character forward is used in calculations)
So this is it, how do I make it rotate just how much 'angleRad' passed from PI/3?
Edit: reads 2*PI/3