Пример #1
0
    public void spawn()
    {
        for (int i = spawnNum; i < maxNum; i++)
        {
            Vector3 HitSpherePos;
            do
            {
                HitSpherePos = new Vector3(this.transform.position.x + Random.Range(-this.transform.lossyScale.x / 2, this.transform.lossyScale.x / 2),
                                           this.transform.position.y + Random.Range(-this.transform.lossyScale.y / 2, this.transform.lossyScale.y / 2),
                                           this.transform.position.z + Random.Range(-this.transform.lossyScale.z / 2, this.transform.lossyScale.z / 2));
            } while (HitSpherePos.magnitude < this.transform.lossyScale.x / 4 || HitSpherePos.y < 1);
            int        whichGhost   = Random.Range(0, ghosts.Length);
            GameObject ghost        = Instantiate(ghosts[whichGhost], HitSpherePos, Quaternion.LookRotation(new Vector3(-1, 0, 0), new Vector3(0, 1, 0))) as GameObject;
            despawn    newDespawner = ghost.AddComponent <despawn>();
            newDespawner.boom = boomMinus;
            if (ghost.gameObject.tag == "good")
            {
                newDespawner.boom = boomPlus;
            }
            newDespawner.lifeTime = 9000;

            steering newSteering = ghost.AddComponent <steering>();
            newSteering.target = steeringTarget;

            // AudioSource newAudio = ghost.AddComponent<AudioSource>();

            // newAudio.playOnAwake = false;
            // newAudio.clip = clip;
            newDespawner.SpawnArea = this.gameObject;
            spawnNum++;
        }
    }
Пример #2
0
    public override steering GetSteering()
    {
        steering steer = new steering();
        int      count = 0;

        //for each boid in the system, check if it is too close
        foreach (GameObject other in targets)
        {
            if (other != null)
            {
                float d = (transform.position - other.transform.position).magnitude;

                if ((d > 0) && (d < desiredSeparation))
                {
                    //calculate vector pointing away from neighbor
                    Vector3 diff = transform.position - other.transform.position;
                    diff.Normalize();
                    diff         /= d;
                    steer.linear += diff;
                    count++;
                }
            }
        }//end for

        if (count > 0)
        {
            //steer.linear /= (float)count;
        }

        return(steer);
    }
Пример #3
0
    public override steering GetSteering()
    {
        steering steer = new steering();
        int      count = 0;

        foreach (GameObject other in targets)
        {
            if (other != null)
            {
                float d = (transform.position - other.transform.position).magnitude;
                if ((d > 0) && (d < neighborDist))
                {
                    steer.linear += other.transform.position;
                    count++;
                }
            }
        }//endfor

        if (count > 0)
        {
            steer.linear /= count;
            steer.linear  = steer.linear - transform.position;
        }

        return(steer);
    }
Пример #4
0
    //run away from the target
    public override steering GetSteering()
    {
        steering steer = new steering();

        steer.linear = transform.position - target.transform.position;
        steer.linear.Normalize();
        steer.linear = steer.linear * agent.maxAccel;
        return(steer);
    }
Пример #5
0
    //update movement for the next frame
    public virtual void LateUpdate()
    {
        velocity += steer.linear * Time.deltaTime;
        rotation += steer.angular * Time.deltaTime;
        if (velocity.magnitude > maxSpeed)
        {
            velocity.Normalize();
            velocity = velocity * maxSpeed;
        }

        if (steer.linear.magnitude == 0.0f)
        {
            velocity = Vector3.zero;
        }
        steer = new steering();
    }
Пример #6
0
 public void SetSteering(steering steer, float weight)
 {
     this.steer.linear  += (weight * steer.linear);
     this.steer.angular += (weight * steer.angular);
 }
Пример #7
0
 // Start is called before the first frame update
 void Start()
 {
     velocity     = Vector3.zero;
     steer        = new steering();
     trueMaxSpeed = maxSpeed;
 }