public void move(Vector2 position) { float distance = Vector3.Distance(transform.position, new Vector3(position.x, position.y)); float time = distance / _speed; Debug.Log(string.Format("Terran Infantry : is moving by going : " + time)); //StopCoroutine(Action()); _moveTime = Time.time; _moveTo = position; _positionCurrent = transform.position; _tweener.Reset(); _tweener.NewTime(time); _currentTweenValue = 0; isTweenFinished = false; //StartCoroutine(Action()); }
public void move(Vector2 position) { _distance = Vector3.Distance(transform.position, new Vector3(position.x, position.y)); float time = _distance / _speed; float dX = position.x - transform.position.x; float dY = position.y - transform.position.y; _positionCurrent = transform.position; alphaRad = Mathf.Atan2(dY, dX); alphaDeg = Mathf.Rad2Deg * alphaRad; alphaDeg = Math.Abs(alphaDeg) > 90 ? alphaDeg - 180 * (dY > 0 ? -1 : 1) : alphaDeg; transform.rotation = Quaternion.Euler(0, 0, alphaDeg); Debug.Log(string.Format("Terran Infantry : is moving by wiggling : " + alphaDeg + "; distance: " + _distance)); //StopCoroutine(Action()); _moveTime = Time.time; _moveTo = position; _directionX = (-90 < alphaDeg && alphaDeg < 90) ? 1 : -1; _directionY = (0 < alphaRad && alphaRad < 180) ? -1 : 1; _tweener.Reset(); _tweener.NewTime(time); _currentTweenValue = 0; //transform.rotation = Quaternion.FromToRotation(_positionCurrent, _moveTo); isTweenFinished = false; //StartCoroutine(Action()); }