// Updates the behaviour
    public override BehaviourResult UpdateBehaviour(AgentActor agent)
    {
        if (agent.m_ballInteractTime <= 0)
        {
            initialised    = false;
            m_ball.touched = false;
            Debug.Log("Suppose to disengage");
            return(BehaviourResult.FAILURE);
        }

        m_seekForce.SetTarget(m_ball.gameObject.transform.position);
        agent.AddForce(m_seekForce.GetForce(agent));


        //currentTarget = -(m_ball.gameObject.transform.position - m_middlePoint).normalized * m_waypointDistance;
        //
        //Vector3 agentPos = agent.gameObject.transform.position;
        //
        //if (m_waypointTarget) {
        //	m_ball.gameObject.GetComponent<Collider> ().enabled = false;
        //	if ((agent.transform.position - currentTarget).sqrMagnitude < 100f)
        //	{
        //		m_waypointTarget = false;
        //		m_ball.gameObject.GetComponent<Collider> ().enabled = true;
        //	}
        //
        //	Debug.Log ("Waypoint Target");
        //
        //	m_seekForce.SetTarget(currentTarget);
        //	agent.AddForce(m_seekForce.GetForce(agent));
        //
        //}
        //
        //if (!m_waypointTarget)
        //{
        //	m_seekForce.SetTarget(m_ball.gameObject.transform.position);
        //	agent.AddForce(m_seekForce.GetForce(agent));
        //
        //	Debug.Log ("Ball Target");
        //
        //	if ((m_ball.gameObject.transform.position - m_middlePoint).sqrMagnitude < 10f) {
        //
        //		initialised = false;
        //		m_ball.touched = false;
        //		return BehaviourResult.FAILURE;
        //	}
        //}



//
//        if ((m_ball.transform.position - m_middlePoint).sqrMagnitude > m_radius)
//        {
//        }
//        else
//        {
//            Bop(agent);
//        }
        return(BehaviourResult.SUCCESS);
    }
    // Updates the behaviour
    public override BehaviourResult UpdateBehaviour(AgentActor agent)
    {
        Vector3 agentPos = agent.gameObject.transform.position;

        //distanceDetection = agent.maxSpeed / 2f;
        //Debug.Log("agent Pos: " + agentPos);
        if ((agentPos - m_waypoints[m_currentWaypointNumber]).sqrMagnitude <= distanceDetection && m_currentWaypointNumber < m_waypoints.Count - 1)
        {
            m_currentWaypointNumber++;
            m_currentTarget = m_waypoints[m_currentWaypointNumber];
            //Debug.Log("Current Target: " + m_waypoints[m_currentWaypointNumber]);
        }
        else if (m_currentWaypointNumber >= m_waypoints.Count - 1)
        {
            if (m_castle != null)
            {
                m_castle.castleTouched = false;
            }
            m_currentWaypointNumber = 0;
            return(BehaviourResult.FAILURE);
        }


        m_seekForce.SetTarget(m_waypoints[m_currentWaypointNumber]);
        agent.AddForce(m_seekForce.GetForce(agent));

        return(BehaviourResult.SUCCESS);
    }
Exemplo n.º 3
0
    // Updates the behaviour
    public override BehaviourResult UpdateBehaviour(AgentActor agent)
    {
        Vector3 agentPos = agent.gameObject.transform.position;

        if ((agentPos - m_currentTarget).sqrMagnitude <= nearEnough)
        {
            Vector2 randomVector = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f));
            randomVector    = randomVector.normalized * Random.Range(0, m_maxRadius) + m_middlePoint;
            m_prevTarget    = m_currentTarget;
            m_aimPrev       = true;
            m_currentTarget = new Vector3(randomVector.x, randomVector.y, Random.Range(-m_maxDepth, m_maxDepth));
        }

        m_seekForce.SetTarget(m_currentTarget);
        agent.AddForce(m_seekForce.GetForce(agent));
        //Debug.Log ("Wander Current Target: " + m_currentTarget);

        //if (m_aimPrev)
        //{
        //    m_rotationalForce.SetTarget(m_prevTarget);
        //    agent.AddForce(m_rotationalForce.GetForce(agent));
        //    if (Vector3.Dot(agent.transform.forward, (agentPos - m_currentTarget)) > 0.8f)
        //        m_aimPrev = false;
        //}
        //else
        //{
        //    m_seekForce.SetTarget(m_currentTarget);
        //    agent.AddForce(m_seekForce.GetForce(agent));
        //    if (m_arrivalForce != null)
        //    {
        //        m_arrivalForce.SetTarget(m_currentTarget);
        //        agent.AddForce(m_arrivalForce.GetForce(agent));
        //    }
        //}


        //foreach (SteeringForce force in m_forces)
        //    agent.AddForce(force.GetForce(agent));

        return(BehaviourResult.SUCCESS);
    }