示例#1
0
    private void OnTriggerStay(Collider other)
    {
        string tag = other.gameObject.tag;

        if ((tag == "playerCopy" && blockPlayerAI) ||
            ((tag == "food" || tag == "poison" || tag == "foodAI") && blockFood))
        {
            ObjectBehaviour objectBehaviour = other.gameObject.GetComponent <ObjectBehaviour>();
            if (objectBehaviour != null)
            {
                Vector3 direction     = objectBehaviour.GetForwardDirection();
                bool    positiveLimit = (forceDirection == ForceDirection.Positive);
                bool    negativeLimit = (forceDirection == ForceDirection.Negative);
                float   theta         = Random.Range(0.0f, 2 * Mathf.PI);
                float   phi           = Random.Range(Mathf.PI / 3, Mathf.PI / 2);
                float   n1            = Mathf.Cos(theta) * Mathf.Cos(phi);
                float   n2            = Mathf.Sin(theta) * Mathf.Cos(phi);
                float   n3            = Mathf.Sin(phi);
                if (forceDirection == ForceDirection.Negative)
                {
                    n3 *= -1;
                }
                switch (verticalAxis)
                {
                case Axis.X:
                    if ((positiveLimit && direction.x < 0.0f) || (negativeLimit && direction.x > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n3, n1, n2));
                    }
                    break;

                case Axis.Y:
                    if ((positiveLimit && direction.y < 0.0f) || (negativeLimit && direction.y > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n2, n3, n1));
                    }
                    break;

                case Axis.Z:
                    if ((positiveLimit && direction.z < 0.0f) || (negativeLimit && direction.z > 0.0f))
                    {
                        objectBehaviour.SetForwardDirecion(new Vector3(n1, n2, n3));
                    }
                    break;
                }
            }
        }
        else if (tag == "player" && other.gameObject.GetComponent <Player>().photonView.isMine)
        {
            if (transform.parent.gameObject.GetComponent <MeshRenderer>() != null)
            {
                transform.parent.gameObject.GetComponent <MeshRenderer>().enabled = true;
            }
        }
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        character       = gameObject.GetComponent <CharacterController>();
        objectBehaviour = gameObject.GetComponent <ObjectBehaviour>();
        //设置一个随机的初始方向
        objectBehaviour.SetForwardDirecion(GetRandomDirection());
        resetCountForWander = 1.0f;


        StartCoroutine(CheckObstacle());
    }
示例#3
0
 protected void Wander()
 {
     resetCountForWander -= Time.deltaTime;
     if (resetCountForWander <= 0.0f)
     {
         float p = Random.Range(0.0f, 1.0f);
         if (p < 0.8f)
         {
             turnHorizontal      = Random.Range(-0.3f, 0.3f);
             turnVertical        = Random.Range(-0.1f, 0.1f);
             resetCountForWander = Random.Range(2.0f, 5.0f);
         }
         else
         {
             Vector3 dir = GetRandomDirection();
             objectBehaviour.SetForwardDirecion(dir);
             turnHorizontal      = 0.0f;
             turnVertical        = 0.0f;
             resetCountForWander = 0.1f;
         }
     }
     objectBehaviour.Turn(turnHorizontal, turnVertical);
     objectBehaviour.Move(ObjectBehaviour.MoveDirection.Front, speed);
 }
示例#4
0
    void TestSetForward()
    {
        Vector3 randomVector = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f));

        testMod.SetForwardDirecion(randomVector);
    }