Ejemplo n.º 1
0
 /// <summary>
 /// Get the target's position where the character will move
 /// </summary>
 private void _GetDestination()
 {
     // Leader node : target is the mouse cursor position
     if (_isLeader)
     {
         _targetGlobalPosition = GetGlobalMousePosition();
     }
     // Node follow another node : target is the node to follow and keep the distance
     else if (_isNodeFollower)
     {
         _targetGlobalPosition = Nucleus_Steering.Steering_CalculateDistanceBetweenFollowers(_nodeToFollow.GlobalPosition, GlobalPosition, Follow_Offset);
     }
     // Node flee : target to run away is the leader position
     else if (_isFlee)
     {
         _targetGlobalPosition = Nucleus_Steering.LeaderToFollow.GlobalPosition;
     }
     // Node follow leader : target is the leader position and keep the distance
     else if (!_isFlee && !_isWander)
     {
         _targetGlobalPosition = Nucleus_Steering.Steering_CalculateDistanceBetweenFollowers(Nucleus_Steering.LeaderToFollow.GlobalPosition, GlobalPosition, Follow_Offset);
     }
     // Stay at the same position
     else if (!_isWander)
     {
         _targetGlobalPosition = GlobalPosition;
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Calculate velocity between the character and the target (cursor), then move the character
    /// </summary>
    private void _MoveCharacter()
    {
        // Perform calcul only if the node have to move
        if (_targetGlobalPosition != GlobalPosition)
        {
            if (_isFlee)
            {
                _velocity = Nucleus_Steering.Steering_Flee(_velocity, GlobalPosition, _targetGlobalPosition, MaxSpeed, FleeRadius, Mass);
            }
            else
            {
                _velocity = Nucleus_Steering.Steering_Seek(_velocity, GlobalPosition, _targetGlobalPosition, MaxSpeed, SlowRadius, Mass);
            }

            // Move the character
            if (_velocity != Nucleus_Utils.VECTOR_0)
            {
                _velocity        = MoveAndSlide(_velocity);
                _sprite.Rotation = _velocity.Angle();   // point the character direction towards the destination
            }
        }
    }