Function only rotates one update-cycle
Hi, i want to turn my cannon before firing and my code currently looks like this:
protected override void Update()
if (Input.GetKeyDown("q") && target && this.currentlySelected)
{
StartCoroutine(TurnTo());
if (canFire && hasTurned) Fire();
}
}
But if I press Q it only rotates about 5°, so I have to spam Q 20+ times to get a 180 rotation. The Coroutine looks like this:
public IEnumerator TurnTo()
{
if (this.moving)
{
yield break;
}
Quaternion targetRotation = Quaternion.LookRotation(targetPos - transform.position);
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotateSpeed);
yield return new WaitForSeconds(2);
}
I used a coroutine bc I also tried to write the 2 lines in front of the Fire() Call and also tried to call TrunTo as a normal methode, but it's the same.
Comment
Your answer
Follow this Question
Related Questions
When to use IEnumerator ? 1 Answer
Nested coroutines 0 Answers
How can we use coroutine inside a function? 2 Answers
Problem with decrement 0 Answers
Implementing Neural Network into Unity. Lots of calculations. 0 Answers