#Various transform in coroutine
1 messages · Page 1 of 1 (latest)
When I press space I execute StartCoroutine(SuperAction())
This is the code:
private IEnumerator SuperAction()
{
//flag for movement
_isMoving = true;
_isGrounded = false;
//wait untill he completly stops
yield return new WaitUntil(() => rb.velocity == Vector3.zero && rb.angularVelocity == Vector3.zero);
//propelled to the air
rb.useGravity = true;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
//stop at predetermined height
yield return new WaitUntil(() => rb.transform.position.y > 5.0f);
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.useGravity = false;
//Does stuff in air
var startTime = Time.time;
while ((Time.time - startTime) < 2)
{
rb.transform.Rotate(new Vector3(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f)) * rotatingSpeed);
yield return new WaitForEndOfFrame();
}
//Set himself to direction ###Seems to stop here and idk why###
var rotationVector = RollToSetFace();
while (rb.transform.eulerAngles != rotationVector)
{
rb.transform.eulerAngles = rotationVector * Time.deltaTime * rotatingSpeed;
}
//To be added: Dice lands facing the correct direction
_isMoving = false ;
_isGrounded = true;
}
}
private Vector3 RollToSetFace() {
var quaternionVector = new Vector3();
switch (1)
{
case 1:
quaternionVector.x = 90;
break;
case 2:
break;
case 3:
quaternionVector.y = -90;
break;
case 4:
quaternionVector.y = 180;
break;
case 5:
quaternionVector.y = 90;
break;
case 6:
quaternionVector.x = -90;
break;
default:
break;
}
return quaternionVector;
}
What is the issue you are running into
The dice spins then it doesn't go past the second while
Sorry it wasn't that clear I marked it with ###
//Set himself to direction ###Seems to stop here and idk why###
var rotationVector = RollToSetFace();
while (rb.transform.eulerAngles != rotationVector)
{
rb.transform.eulerAngles = rotationVector * Time.deltaTime * rotatingSpeed;
}
stops here