hey hey, first of all :i know that this kind of question has been asked many times before. i want to say that i was reading and then trying much to adapt it to my need but i didnt come to a solution.
i have a script in which the y component of transform.eulerangles is changed in an IEnumerator function using there a coroutine.
IEnumerator y_rotation()
{
while (true) // run this forever and ever
{
if (is_attacked == true) // if in attack mode, do rotation logic
{
//yRotation = Mathf.SmoothDamp(0,-90,ref Velocity,transTime);
yRotation = -90.0f;
yield return StartCoroutine(Wait());
yRotation = 90.0f;
yield return StartCoroutine(Wait());
}
yield return null; // wait a single frame to let Unity breath
}
}
which is executed in FixedUpdate :
void FixedUpdate()
{
transform.eulerAngles = new Vector3(0, yRotation, 0);
rb.AddRelativeForce(Vector3.forward * thrust);
rb.velocity = transform.forward * rb.velocity.magnitude;
}
what i want to achiefe is that it takes about 1 second until yRotation = -90
i’ve tried it with mathf.lerp or mathf.smoothdamp nothing works, i even tried it with a for loop (…i++)
but the value is in a while loop ! so my pc went on strike. I’m pretty confused now so i would be thankfully for any help.