- Home /
How to Rotate camera around object SMOOTHLY when using Input.GetKeyDown
I've searched on the forum and still cant find how to do this, my problem is that i'm trying to make the camera rotate around the character smoothly with GetKeyDown, but that does not seems to work at all, the camera simply rotate instantly here some code that i have tested:
private void RotateHorizontaly(bool left)
{
float direction = 1;
if (!left)
direction *= -1;
transform.RotateAround(target.position, Vector3.up, horizontalAngleDegree * direction);
}
target is the player and this method makes the rotation, and works fine but not smoothly, i used a float direction and a boolean to switch the rotate orientaion when its clokedwised or anticlokedwised, i'm calling this method on a LateUpdate() like this:
private void LateUpdate()
{
FollowTarget();
if (Input.GetKeyDown(KeyCode.Q))
{
RotateHorizontaly(true);
}
else if (Input.GetKeyDown(KeyCode.E))
{
RotateHorizontaly(false);
}
}
But that does not make the behavior i want, i already tried using Quaternion.Slerp and Lerp but that makes the camera go wild.
The camera is like this:
and i want X rotation and Y position to stay that way, just the Y rotation to move and face the character, can anyone help me?
Answer by rrabi · Aug 13, 2017 at 01:43 AM
One way would be to create an animation for the camera in which you are only changing the rotation of the camera, and then just play the animation on key down and stop it on key up
Your answer
Follow this Question
Related Questions
Help, please with rotation input 0 Answers
Mathf.Clamp is 'Sticky'? 1 Answer
Mouse Orbit snapping issues 0 Answers
Making an object rotate around a sphere 1 Answer
Mouse control rotate around player 0 Answers