How do I do my camera player look at an specific direction when key pressed
I have a third-person camera controller that follows my player and moves with the x-axis of my mouse around it, but I want to write a code that when I press a key, the camera rotates smoothly facing the front of my player no matter where the camera is located. I have tried a lot and find a solution, I think the best way is with a quaternion but I dont know how, please help
Here is the code im using
public class ThirdPersonCameraController : MonoBehaviour { public Vector3 Offset; private Transform target; public float sensibility; [Range(0,1)] public float lerpValue;
void Start()
{
target = GameObject.Find("Kira").transform;
}
void LateUpdate()
{
transform.position = Vector3.Lerp(transform.position, target.position + Offset, lerpValue); //Soft movement of camera
Offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * sensibility, Vector3.up) * Offset; // add up angle controlled by mouse position to offset
if (Input.GetKey(KeyCode.F))
{
// When press F camera face at the front of player
//>> here is where I want this happen
}
else
{
transform.LookAt(target); //Camera look at the player
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612225003im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Camera spawn rotate with object 0 Answers
i am tying to build a fps controller from scratch and cant seem to get him to look up or down 0 Answers
(NEED HELP!) Camera controlled by mouse Y, player controlled by mouse X 2 Answers
Camera rotation on mouse input 0 Answers
camera location + rotation & object location and rotation. 0 Answers