/// <summary> /// Moves the character towards the target if needed /// </summary> protected virtual void Move() { if (_brain.Target == null) { return; } if (this.transform.position.x < _brain.Target.position.x) { _characterMovement.SetHorizontalMovement(1f); } else { _characterMovement.SetHorizontalMovement(-1f); } if (this.transform.position.y < _brain.Target.position.y) { _characterMovement.SetVerticalMovement(1f); } else { _characterMovement.SetVerticalMovement(-1f); } if (Mathf.Abs(this.transform.position.x - _brain.Target.position.x) < MinimumDistance) { _characterMovement.SetHorizontalMovement(0f); } if (Mathf.Abs(this.transform.position.y - _brain.Target.position.y) < MinimumDistance) { _characterMovement.SetVerticalMovement(0f); } }
/// <summary> /// This method initiates all the required checks and moves the character /// </summary> protected virtual void Patrol() { _waitingDelay -= Time.deltaTime; if (_character == null) { return; } if ((_character.ConditionState.CurrentState == CharacterStates.CharacterConditions.Dead) || (_character.ConditionState.CurrentState == CharacterStates.CharacterConditions.Frozen)) { return; } if (_waitingDelay > 0) { _characterMovement.SetHorizontalMovement(0f); _characterMovement.SetVerticalMovement(0f); return; } // moves the agent in its current direction CheckForObstacles(); CurrentPathIndex = _mmPath.CurrentIndex(); if (CurrentPathIndex != _indexLastFrame) { LastReachedPatrolPoint = _mmPath.CurrentPoint(); _waitingDelay = _mmPath.PathElements[CurrentPathIndex].Delay; if (_waitingDelay > 0) { _characterMovement.SetHorizontalMovement(0f); _characterMovement.SetVerticalMovement(0f); _indexLastFrame = CurrentPathIndex; return; } } _direction = _mmPath.CurrentPoint() - this.transform.position; _direction = _direction.normalized; _characterMovement.SetHorizontalMovement(_direction.x); _characterMovement.SetVerticalMovement(_direction.z); _indexLastFrame = CurrentPathIndex; }
/// <summary> /// On exit state we stop our movement /// </summary> public override void OnExitState() { base.OnExitState(); _characterMovement.SetHorizontalMovement(0f); _characterMovement.SetVerticalMovement(0f); }
/// <summary> /// On exit state we stop our movement /// </summary> public override void OnExitState() { base.OnExitState(); _characterPathfinder3D.SetNewDestination(null); _characterMovement.SetHorizontalMovement(0f); _characterMovement.SetVerticalMovement(0f); }
/// <summary> /// Moves the character towards the target if needed /// </summary> protected virtual void Move() { if (_brain.Target == null) { return; } _directionToTarget = _brain.Target.position - this.transform.position; _movementVector.x = _directionToTarget.x; _movementVector.y = _directionToTarget.z; _characterMovement.SetMovement(_movementVector); if (Mathf.Abs(this.transform.position.x - _brain.Target.position.x) < MinimumDistance) { _characterMovement.SetHorizontalMovement(0f); } if (Mathf.Abs(this.transform.position.z - _brain.Target.position.z) < MinimumDistance) { _characterMovement.SetVerticalMovement(0f); } }