- Home /
Question by
EricsUnityAccount · Jun 03 at 09:40 PM ·
rotationrigidbodyrotate3rd person controller3rd person camera
How to make the character move and rotate where the camera is facing (3rd person)
I have a 3rd person character controller I'm trying to make, but I cant get the character to, 1. rotate to a different direction while moving, and 2. move where the camera is facing ex: looking back and pressing w moves toward the camera instead of away.
I am using the new input system and cinemachine. I think fixing the second issue might fix the first but I'm not sure. Any help would be apricated.
This is my rotation code, let me know if more code or info is needed.
float rotationFactorPerFrame = 15f;
void handleRotation()
{
Vector3 positionToLookAt;
positionToLookAt.x = currentMovement.x;
positionToLookAt.y = 0.0f;
positionToLookAt.z = currentMovement.z;
Quaternion currentRotation = transform.rotation;
if (isMovementPressed)
{
Quaternion targetRotation = Quaternion.LookRotation(positionToLookAt);
transform.rotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * Time.deltaTime);
}
}
Comment