- Home /
Rotate camera smoothly for particular position with single INPUT
I'm trying to rotate the Main camera which is child of the character.
And I have to rotate that with single Input which means single press of left or right Arrow Key.
Character may in XXX angle and have to rotate the Main camera left and right of the character 45 degree
But I did this through continuous pressing of left and right arrow keys in C#... Now I'm trying this with single press it have to rotate smoothly for particular angle.
This is normal image in some angle
Like this, I have to rotate camera smoothly for particular angle with single press of left and right Arrow key.
This is getting too late to finish...so lets see which adroit will answer for this...thanks ..
add a bool, when you press the key make the boolean true. when the boolean is true the camera lerps to the right place.
Finally I got Code In Js but I need this in C#....! private var qTo = Quaternion.identity;
function Update () {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A)) {
rotation += 45.0;
qTo = Quaternion.Euler(0.0,rotation,0.0);
}
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) {
rotation -= 45;
qTo = Quaternion.Euler(0.0, rotation,0.0);
}
transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speed * Time.deltaTime);
Is there any one to convert this in C#. . . !
I did, but rising Errors. . .
private Quaternion qTo = Quaternion.identity;
.
.
.
public GameObject qTo;
void Update () {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A)) {
rotation += 45.0f;
qTo = Quaternion.Euler(0.0f,rotation,0.0f);
}
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) {
rotation -= 45;
qTo = Quaternion.Euler(0.0f, rotation,0.0f);
}
}
C# :)
I did same as this but raises error... :-(
The best overloaded method match for
UnityEngine.Quaternion.Euler(float, float, float)' has some invalid arguments - Argument
#1' cannot convertdouble' expression to type
float' These both errors are in qTo line only...
rotation is not a float thats why.. where have u declared the rotation variable? put this at the top
public float rotation = 0.0f;