Sorry for saturating the forum, but I couldn’t find any results after an hour of searching for a solution. I assume that’s why my question was taken down last time without being posted at all, but I really do need some help from anyone willing. I can make it work if I don’t hold down the buttons, but I believe that implementing this feature will help make the game more intuitive as opposed to adjusting the angle by 5 degrees every time you press up or down.
Edit: Furthermore, I forgot to mention that when I press the up and down keys, the engine crashes.
Any help is greatly appreciated.
void UpThing()
{
Vector3 direction = new Vector3(0, 0, 1);
targetRotation *= Quaternion.AngleAxis(-5, direction);
}
void DownThing()
{
Vector3 direction = new Vector3(0, 0, 1);
targetRotation *= Quaternion.AngleAxis(5, direction);
}
void Update()
{
if (Input.GetKeyDown("up"))
{
up = true;
}
if (Input.GetKeyUp("up"))
{
up = false;
}
while(up)
{
InvokeRepeating("UpThing", 1f, 1f);
}
if (Input.GetKeyDown("down"))
{
down = true;
}
if (Input.GetKeyUp("up"))
{
down = false;
}
while (down)
{
InvokeRepeating("DownThing", 1f, 1f);
}
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 10 * smooth * Time.deltaTime);
}