// Update is called once per frame void Update() { if (Waypoints == null) { return; } if (_collide && _detectCollision.IsColliding()) { return; } var distance = Vector3.Distance(transform.position, CurrentWaypoint.transform.position); if (distance < 0.5f) { var _next = Waypoints.GetNextWayPoint(CurrentWaypoint.index); if (_next != null) { CurrentWaypoint = _next; } } var lookDir = CurrentWaypoint.transform.position - transform.position; Quaternion lookAt = Quaternion.LookRotation(lookDir.normalized, Vector3.forward); var rot = Quaternion.RotateTowards(_renderer.transform.rotation, lookAt, _turnRate); rot.y = 0; rot.x = 0; //_renderer.transform.rotation = rot; transform.rotation = rot; CurrentWaypoint.transform.position = new Vector3(CurrentWaypoint.transform.position.x, CurrentWaypoint.transform.position.y, 0); transform.position = Vector3.MoveTowards(transform.position, CurrentWaypoint.transform.position, _speed * Time.deltaTime); }
// Update is called once per frame void Update() { var distance = Vector3.Distance(transform.position, _currentWaypoint.transform.position); if (distance < 0.5f) { _currentWaypoint = _waypoints.GetNextWayPoint(_currentWaypoint.index); } Quaternion lookAt = Quaternion.LookRotation(_currentWaypoint.transform.position, Vector3.forward); var rot = Quaternion.RotateTowards(_renderer.transform.rotation, lookAt, 90f); rot.y = 0; rot.x = 0; // _renderer.transform.rotation = rot; transform.position = Vector3.MoveTowards(transform.position, _currentWaypoint.transform.position, 0.1f); }