0 votes

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:
    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

Godot version 3.2.3
in Engine by (26 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.