Hi! I have a boat that I’m trying to get to move around my map randomly. I have two coroutines. One for movement and one for rotation. Both are called as soon as the game starts. The movement code is:
IEnumerator Move() {
yield return new WaitForSeconds (0.05f);
transform.position += Vector3.forward * Time.deltaTime * thrust;
StartCoroutine (Move ());
}
The rotation one is exactly the same except the wait time is longer and the code I’m using is:
Vector3 euler = transform.eulerAngles;
euler.z = Random.Range(0f, 360f);
transform.eulerAngles = euler;
However this of course makes the ship instantly rotate but I’ve yet to find a way to make the rotation gradual while still keeping it random. That’s the first issue. Secondly, when the ship does rotate it doesn’t change movement direction. That is, if the ship is heading, say north and the random rotation flips it around, it will continue heading north, even if the bow is facing the opposite direction. I thought the code I have would account for that but apparently somethings wrong. I’m really just focused on the first problem and I think eventually I could figure out the second, but I figured if I’m posting one, why not post the other?
Thanks!