- Home /
Question by
Ercova · Aug 05, 2021 at 07:44 AM ·
movementtransformcontrollercharacter controllerlean
How can i write this Code with Character Controller
Hello. I have This code for leaning character with Transform. But how can i make this function with Character controller. I have Already character controller and move character "Forward, left and right" with this controller. Any help appreciated.
void Lean(float tilt)
{
Vector3 eulerAngles = transform.localRotation.eulerAngles;
eulerAngles.z = tilt;
eulerAngles.y = -tilt * 2;
Quaternion targetRotation = Quaternion.Euler(eulerAngles);
float speed = 100 * Time.deltaTime;
transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, speed);
}
Comment
i thought i may use that function like controller.move().. But i've learnt that character controller is not handle rotation. So yeah i got it.