Example #1
0
    void AgentMove()
    {
        //if (seeker.destination == m_destination)
        //    return;

        if (!m_walking)
        {
            return;
        }

        agent.destination = m_destination;

        Vector3    nextPosition;
        Quaternion nextRotation;

        agent.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation);
        if (!controller)
        {
            deltaPosition = new Vector3(animator.rootPosition.x, nextPosition.y, animator.rootPosition.z);
        }
        //deltaPosition = nextPosition;
        else
        {
            deltaPosition = new Vector3(animator.rootPosition.x, nextPosition.y, animator.rootPosition.z);
            //deltaPosition = nextPosition;
            Vector3 delta = controller.CalculateMovementDelta(animatedObject.transform.position, Time.deltaTime);
            deltaPosition = new Vector3(deltaPosition.x + delta.x, deltaPosition.y, deltaPosition.z + delta.z);
        }

        agent.FinalizeMovement(deltaPosition, nextRotation);
        transform.rotation = nextRotation;

        //if (agent.destination == m_destination)
        //    return;

        //agent.destination = m_destination;
        //if (agent.pathStatus == NavMeshPathStatus.PathInvalid || agent.pathStatus == NavMeshPathStatus.PathPartial)
        //{
        //    m_walking = false;
        //    agent.isStopped = true;
        //    return;
        //}

        //if (agent.isStopped)
        //    agent.isStopped = false;

        //m_walking = true;
        //agent.nextPosition = animatedObject.transform.position;
        //transform.rotation = agent.transform.rotation;
    }
Example #2
0
    public virtual bool MoveToPosition()
    {
        // Calculate how the AI wants to move
        ai.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation);

        localDesiredVelocity = transform.InverseTransformDirection(ai.desiredVelocity);

        localDesiredVelocity.y = 0; // we don't want our player floating so ignore y axis

        if (!useRootPosition)
        {
            ai.FinalizeMovement(transform.position, nextRotation);
        }
        else
        {
            transform.position = anim.rootPosition;
        }
        if (!useRootRotation)
        {
            transform.rotation = nextRotation;
        }
        else
        {
            transform.rotation = anim.rootRotation;
        }

        angle = Player.Utility.FindSignedAngle(transform.forward, (ai.steeringTarget - transform.position));

        EnableMovement();
        // Update animation parameters
        UpdateMoveAnimations(localDesiredVelocity, angle, shouldMove);
        if (Vector3.Distance(ai.destination, transform.position) <= ai.endReachedDistance)
        {
            DisableMovement();
            Debug.Log("Reached Objective");
            return(true);
        }

        return(false);
    }
Example #3
0
    public virtual bool MoveToPosition()
    {
        _blackboard.targetReachedStatus = false;
        // Calculate how the _ai wants to move
        _ai.MovementUpdate(Time.deltaTime, out _nextPosition, out _nextRotation);

        _localDesiredVelocity = transform.InverseTransformDirection(_ai.desiredVelocity);

        _localDesiredVelocity.y = 0; // we don't want our player floating so ignore y axis

        if (!useRootPosition)
        {
            _ai.FinalizeMovement(transform.position, _nextRotation);
        }
        else
        {
            transform.position = _anim.rootPosition;
        }
        if (!useRootRotation)
        {
            transform.rotation = _nextRotation;
        }
        else
        {
            transform.rotation = _anim.rootRotation;
        }

        _angle = Player.Utility.FindSignedAngle(transform.forward, (_ai.steeringTarget - transform.position));

        EnableMovement();
        if (Vector3.Distance(_ai.destination, transform.position) <= _ai.endReachedDistance)
        {
            _blackboard.targetReachedStatus = true;
            DisableMovement();
            return(true);
        }

        return(false);
    }