예제 #1
0
    bool HandleCheckMoveFn(GameObject _who, Vector3 _from, ref Vector3 _to)
    {
        MovementScript body = _who.GetComponent <MovementScript> ();

        //block rvo if is doing work
        if (_who.GetComponent <MovementScript> ().m_isDoingWork)
        {
            return(false);
        }

        _who.GetComponent <MovementScript> ().m_rvoDir  = GlobalScript.GetDirection(_who.transform.position, _to);
        _who.GetComponent <MovementScript> ().m_rvoDisp = GlobalScript.GetDistance(_who.transform.position, _to);
        _who.GetComponent <WNS_AnimationControllerScript>().HandleSpeedChange(GlobalScript.GetDistance(_to, _from));

        //kill small rvo displacements
//hardcoded prototype
        if (GlobalScript.GetDistance(_from, _to) < 0.25f * _who.GetComponent <MovementScript> ().m_maxSpeed)
        {
            _to = _from;
        }

//		if (body.m_waypointIsStrict && GlobalScript.GetAngle(body.m_rvoDir,m_currentWpDirection) > 90)
//			_to = _from;


        return(true);
    }
예제 #2
0
    void Rotate()
    {
        if (m_waypointIsStrict)
        {
            m_desiredDirection = GlobalScript.GetDirection(transform.position, m_currentWaypoint);
        }
        else
        {
            m_desiredDirection = GlobalScript.GetDirection(transform.position, m_lookAheadPoint);
        }

//hardcoded prototype
//		m_angle = (GlobalScript.GetAngle(m_rvoDir,m_desiredDirection) - 90)/180;
//		m_angle = Mathf.Clamp01 (m_angle);
//		m_angle = 1f;
        m_rvoWeight = Mathf.Clamp01(m_rvoDisp / m_maxSpeed) / 2f;       // * m_angle;
        m_direction = (m_rvoWeight * m_rvoDir + (1 - m_rvoWeight) * m_direction).normalized;

        if (!m_isMoving)
        {
            if (GlobalScript.GetAngle(m_desiredDirection, m_direction) < m_maxAngularRotationSpeed)
            {
                m_isMoving = true;
            }
        }


        if (GlobalScript.GetAngle(m_desiredDirection, m_direction) > 1f)
        {
            m_direction = Vector3.Slerp(m_direction, m_desiredDirection, m_maxAngularRotationSpeed / (GlobalScript.GetAngle(m_direction, m_desiredDirection)));
        }
        transform.rotation = Quaternion.LookRotation(m_direction);
    }
예제 #3
0
    void Move()
    {
        m_wpDistance         = GlobalScript.GetDistance(transform.position, m_currentWaypoint);
        m_currentWpDirection = GlobalScript.GetDirection(transform.position, m_currentWaypoint);
        UpdateLookAheadPoint();
        Rotate();
        m_prevFrameLocation = transform.position;

        AdjustSpeed();


        if (m_isMoving)
        {
            transform.position += m_direction * m_speed;
        }
        if (m_animationScript && !m_rvoScript)
        {
            m_animationScript.HandleSpeedChange(GlobalScript.GetDistance(transform.position, m_prevFrameLocation));
        }
    }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        SetUpRoute();
        m_prevWaypoint     = m_currentWaypoint;
        m_desiredDirection = m_direction = GlobalScript.GetDirection(transform.position, m_currentWaypoint);
        m_animationScript  = GetComponent <WNS_AnimationControllerScript> ();
        m_rvoScript        = GetComponent <RVOUnity> ();
        m_maxSpeed         = m_speed;
        if (m_animationScript == null)
        {
            print("Animation script it detached");
        }

        if (m_rvoScript == null)
        {
            print("RVO script it detached");
        }
        else
        {
            RVOUnityMgr.GetInstance("").SetCheckMoveFn(HandleCheckMoveFn);
        }
    }
예제 #5
0
    //Move look ahead point
    void UpdateLookAheadPoint()
    {
        m_rawLookAheadPoint = GlobalScript.PredictPointInDirection(transform.position, m_direction, lookAheadDistance);

        if (!m_waypointIsStrict)
        {
            if (GlobalScript.GetTwoLinesIntersection(transform.position, m_rawLookAheadPoint, m_prevWaypoint, m_currentWaypoint, ref m_intersectionPoint))
            {
                m_overflowAmount = lookAheadDistance - GlobalScript.GetDistance(transform.position, m_intersectionPoint);
                if (m_overflowAmount > 0)
                {
                    if (GlobalScript.GetDistance(m_intersectionPoint, m_currentWaypoint) < m_wpDistance)
                    {
                        m_overflowAmount = Mathf.Min(m_overflowAmount, m_speed * lookAheadDistance / 10);
                        m_lookAheadPoint = m_intersectionPoint + m_crossWpDirection * m_overflowAmount;
                        return;
                    }
                }
            }
            m_lookAheadPoint = transform.position + GlobalScript.GetDirection(transform.position, m_currentWaypoint) * lookAheadDistance;
        }
    }
예제 #6
0
    //Pick new waypoint
    bool TryPickNewWaypoint()
    {
        if (m_arrayReadingDirection)
        {
            m_currentWaypointIndex++;
        }
        else
        {
            m_currentWaypointIndex--;
        }
        if (m_currentWaypointIndex == m_arrayOverflowIndex)
        {
            return(false);
        }

        m_prevWaypoint     = m_currentWaypoint;
        m_currentWaypoint  = m_waypoints [m_currentWaypointIndex].transform.position;
        m_crossWpDirection = GlobalScript.GetDirection(m_prevWaypoint, m_currentWaypoint);
        if (m_waypointIsStrict)
        {
            m_desiredDirection = GlobalScript.GetDirection(transform.position, m_currentWaypoint);
        }

        if ((m_waypoints [m_currentWaypointIndex]).GetComponent <WaypointScript> ())
        {
            m_waypointIsStrict         = (m_waypoints [m_currentWaypointIndex]).GetComponent <WaypointScript> ().isStrict;
            m_strictWpReachingDistance = (m_waypoints [m_currentWaypointIndex]).GetComponent <WaypointScript> ().reachingDistance;
            m_strictWpApproachingRange = (m_waypoints [m_currentWaypointIndex]).GetComponent <WaypointScript> ().approachingRange;
        }

        if (m_waypointIsStrict)
        {
            m_workIsDone = false;
        }

        return(true);
    }