Пример #1
0
    void FixedUpdate()
    {
        Vector3 accel = steeringBasics.arrive(targetPosition);

        steeringBasics.steer(accel);
        steeringBasics.lookWhereYoureGoing();
    }
Пример #2
0
    public Vector3 getSteering(ICollection <MovementAIRigidbody> targets)
    {
        Vector3 centerOfMass = Vector3.zero;
        int     count        = 0;

        /* Sums up everyone's position who is close enough and in front of the character */
        foreach (MovementAIRigidbody r in targets)
        {
            if (steeringBasics.isFacing(r.position, facingCosineVal))
            {
                centerOfMass += r.position;
                count++;
            }
        }

        if (count == 0)
        {
            return(Vector3.zero);
        }
        else
        {
            centerOfMass = centerOfMass / count;

            return(steeringBasics.arrive(centerOfMass));
        }
    }
Пример #3
0
    public Vector3 getSteering(MovementAIRigidbody target, Vector3 offset, out Vector3 targetPos)
    {
        Vector3 worldOffsetPos = target.position + target.transform.TransformDirection(offset);

        //Debug.DrawLine(transform.position, worldOffsetPos);

        /* Calculate the distance to the offset point */
        Vector3 displacement = worldOffsetPos - transform.position;
        float   distance     = displacement.magnitude;

        /* Get the character's speed */
        float speed = rb.velocity.magnitude;

        /* Calculate the prediction time */
        float prediction;

        if (speed <= distance / maxPrediction)
        {
            prediction = maxPrediction;
        }
        else
        {
            prediction = distance / speed;
        }

        /* Put the target together based on where we think the target will be */
        targetPos = worldOffsetPos + target.velocity * prediction;

        return(steeringBasics.arrive(targetPos));
    }
Пример #4
0
    public Vector3 getSteering(MovementAIRigidbody target, ICollection <MovementAIRigidbody> obstacles, out Vector3 bestHidingSpot)
    {
        //Find the closest hiding spot
        float distToClostest = Mathf.Infinity;

        bestHidingSpot = Vector3.zero;

        foreach (MovementAIRigidbody r in obstacles)
        {
            Vector3 hidingSpot = getHidingPosition(r, target);

            float dist = Vector3.Distance(hidingSpot, transform.position);

            if (dist < distToClostest)
            {
                distToClostest = dist;
                bestHidingSpot = hidingSpot;
            }
        }

        //If no hiding spot is found then just evade the enemy
        if (distToClostest == Mathf.Infinity)
        {
            return(evade.getSteering(target));
        }

        //Debug.DrawLine(transform.position, bestHidingSpot);

        return(steeringBasics.arrive(bestHidingSpot));
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        Vector3 target = flowers.SeekFlower();
        Vector3 accel  = steeringBasics.arrive(target);

        steeringBasics.steer(accel);
        steeringBasics.lookWhereYoureGoing(target);
    }
Пример #6
0
    private void Arrive(GameObject dest)
    {
        Vector2 accel = new Vector2(0, 0);         // TODO: Tighten this up, we're creating a LOT of new Vector2s here...

        if (destination != null)
        {
            accel = _steeringBasics.arrive(dest.transform.position);
        }

        _steeringBasics.steer(accel);
        _steeringBasics.lookWhereYoureGoing();
    }
Пример #7
0
    void FixedUpdate()
    {
        if (barProgress <= 0 && f.done)
        {
            Map m = GameObject.Find("Map").GetComponent <Map>();
            m.spawn(1);
            Destroy(gameObject);
        }

        if (player == null)
        {
            return;
        }

        float distToPlayer = Vector3.Distance(player.position, transform.position);

        if (!f.done || distToPlayer > awakeDist)
        {
            rb.velocity = Vector3.zero;
            return;
        }

        if (Vector3.Distance(player.position, transform.position) <= explodeDist)
        {
            player.GetComponent <Health>().applyDamage(explodeDmg);
            applyDamage(10000000f);

            Instantiate(explosionPrefab, transform.position, Quaternion.identity);

            rb.velocity = Vector3.zero;

            Camera.main.GetComponent <CameraMovement>().shake = 0.05f;
        }

        Vector3 accel = wallAvoidance.getSteering();

        if (accel.magnitude < 0.005f)
        {
            accel = steeringBasics.arrive(player.position);
        }

        steeringBasics.steer(accel);
        steeringBasics.lookWhereYoureGoing();
    }
Пример #8
0
    public Vector3 getSteering(LinePath path, bool pathLoop, out Vector3 targetPosition)
    {
        // If the path has only one node then just go to that position;
        if (path.Length == 1)
        {
            targetPosition = path[0];
        }
        // Else find the closest spot on the path to the character and go to that instead.
        else
        {
            /* Get the param for the closest position point on the path given the character's position */
            float param = path.getParam(transform.position, rb);

            //Debug.DrawLine(transform.position, path.getPosition(param, pathLoop), Color.red, 0, false);

            if (!pathLoop)
            {
                Vector3 finalDestination;

                /* If we are close enough to the final destination then stop moving */
                if (isAtEndOfPath(path, param, out finalDestination))
                {
                    targetPosition = finalDestination;

                    rb.velocity = Vector3.zero;
                    return(Vector3.zero);
                }
            }

            /* Move down the path */
            param += pathDirection * pathOffset;

            /* Set the target position */
            targetPosition = path.getPosition(param, pathLoop);

            //Debug.DrawLine(transform.position, targetPosition, Color.red, 0, false);
        }

        return(steeringBasics.arrive(targetPosition));
    }
Пример #9
0
    public Vector3 getSteering(LinePath path, bool pathLoop, out Vector3 targetPosition)
    {
        // If the path has only one node then just go to that position;
        if (path.Length == 1)
        {
            targetPosition = path[0];
        }
        // Else find the closest spot on the path to the character and go to that instead.
        else
        {
            if (!pathLoop)
            {
                /* Find the final destination of the character on this path */
                Vector2 finalDestination = (pathDirection > 0) ? path[path.Length - 1] : path[0];

                /* If we are close enough to the final destination then either stop moving or reverse if
                 * the character is set to loop on paths */
                if (Vector2.Distance(transform.position, finalDestination) < stopRadius)
                {
                    targetPosition = finalDestination;

                    rb.velocity = Vector2.zero;
                    return(Vector2.zero);
                }
            }

            /* Get the param for the closest position point on the path given the character's position */
            float param = path.getParam(transform.position);

            /* Move down the path */
            param += pathDirection * pathOffset;

            /* Set the target position */
            targetPosition = path.getPosition(param, pathLoop);
        }

        return(steeringBasics.arrive(targetPosition));
    }