Пример #1
0
    void updateAbduct()
    {
        // set velocity to 0
        rb.velocity = new Vector3(0, 0, 0);

        // Check whether sheep has somehow died
        if (sheepChaseTarget == null)
        {
            endAbducting();
            randomNextActivity();
            return;
        }

        // check whether sheep is out of abduction range
        Vector3 sheepToAngel = transform.position - sheepChaseTarget.transform.position;

        if (sheepToAngel.magnitude > abductStopDist)
        {
            endAbducting();
            randomNextActivity();
            return;
        }

        // check whether sheep is close enough to disappear
        if (sheepToAngel.magnitude < abductDoneDist)
        {
            // spawn particle effect
            Instantiate(abductionBurst, sheepChaseTarget.transform.position, sheepChaseTarget.transform.rotation);

            // disappear sheep
            hsm.objectDrop(sheepChaseTarget);

            // move out of abduction mode
            endAbducting();
            randomNextActivity();
            return;
        }

        // update beam
        var points = new Vector3[2];

        points[0] = transform.position;
        points[1] = sheepChaseTarget.transform.position;
        lineRenderer.SetPositions(points);

        // update sheep velocity
        Rigidbody sheepRB = sheepChaseTarget.GetComponent <Rigidbody>();

        sheepRB.velocity = (sheepToAngel / sheepToAngel.magnitude) * abductSpeed;

        // TODO turn towards sheep
    }
Пример #2
0
    void Update()
    {
        //Check if fallen off
        if (rb.position.y < -10)
        {
            hsm.objectDrop(this.gameObject);
        }

        // If countdown ended, move in direction of goal.
        if (moveCountdown <= 0 && isOnGround)
        {
            Vector3 goalHop = new Vector3(goal.x, hopForce, goal.z);
            g2 = goalHop;
            rb.AddForce(goalHop, ForceMode.VelocityChange);
            isOnGround = false;

            Vector3 horizontalVelocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
            if (horizontalVelocity.magnitude > maxSheepSpeed)
            {
                horizontalVelocity = horizontalVelocity.normalized * maxSheepSpeed;
                rb.velocity        = new Vector3(horizontalVelocity.x, rb.velocity.y, horizontalVelocity.z);
            }

            moveCountdown = Random.Range(minStartCountdown, maxStartCountdown);

            goal.y = 0; // goal is on same plane as sheep
        }
        // if a move countdown has passed but it hasn't hit the ground, just assume it's on ground
        // TODO fix this; leaving it out makes sheep freeze, letting them hop when not on ground causes flying sheep
        else if (moveCountdown <= 0 && !isOnGround && rb.velocity.y > fallingThreshold)
        {
            moveCountdown = Random.Range(minStartCountdown, maxStartCountdown);
            isOnGround    = true;
            afterHop();
        }
        else
        {
            moveCountdown -= Time.deltaTime;
        }

        // Debug line to show goal; click on "gizmos" button to show/hide
        Debug.DrawLine(transform.position, transform.position + goal * 0.3f, Color.red);
    }