So for the Enemy State lesson of the Combat course section, I have the slimes moving around, but every once in awhile they will start spinning as well as moving. I followed the instructions in the lesson and have the same code so not sure why this is happening.
Enemy AI class
private IEnumerator RoamingRouting()
{
while (_state == State.Roaming)
{
var roamPos = GetRoamingPosition();
_enemyPathfinding.MoveTo(roamPos);
yield return new WaitForSeconds(2f);
}
}
private Vector2 GetRoamingPosition()
{
return new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;
}
EnemyPathfinding Class
private void FixedUpdate()
{
Move();
}
private void Move()
{
_rigidbody.MovePosition(_rigidbody.position + _moveDir * (_moveSpeed * Time.fixedDeltaTime));
}
public void MoveTo(Vector2 targetPos)
{
_moveDir = targetPos;
}
What is causing the spin to happen?