Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        myInputDevice = deviceAssigner.
                        GetComponent <DeviceAssigner>().GetPlayerDevice(playerIndex);

        if (myInputDevice == null)
        {
            return;
        }

        float horizontal = 0f, vertical = 0f;

        // get the axis values, construct a vector and normalize it
        if (aimStick == Stick.LEFTSTICK)
        {
            horizontal = myInputDevice.LeftStickX;
            vertical   = myInputDevice.LeftStickY;
        }
        else if (aimStick == Stick.RIGHTSTICK)
        {
            horizontal = myInputDevice.RightStickX;
            vertical   = myInputDevice.RightStickY;
        }


        moveVector = new Vector3(horizontal, vertical, 0f);


        if (moveVector.magnitude > radialDeadZone)
        {
            var currentRot = Quaternion.LookRotation(Vector3.forward, moveVector);
            var newRot     = Quaternion.Lerp(transform.rotation, currentRot,
                                             Time.deltaTime * angularVelocity);

            transform.rotation = newRot;
        }

        VirusPosManager pm = GetComponentInParent <VirusPosManager> ();

        if (pm)
        {
            pm.facing = transform.up;
        }
//		if(moveVector.magnitude != 0f){
//			transform.up = moveVector;
//		}
    }
Esempio n. 2
0
    bool ReachingSpreadRadius(Transform virusTrans)
    {
        VirusPosManager vpm    = virusTrans.GetComponentInChildren <VirusPosManager>();
        float           radius = 0f;

        if (vpm)
        {
            radius = vpm.spreadRadius;
        }
        if (virusTrans == null)
        {
            return(true);
        }
        float dist = Vector3.Distance(transform.position, virusTrans.position);

        // 0.75 is a magic number
        return(dist >= 0.75 * radius);
    }
Esempio n. 3
0
    // logic for switching states
    void Update()
    {
        //ObjectIdentity oi = transform.parent.GetComponent<ObjectIdentity> ();


        //if (oi == null)
        //return;
        switch (cs.controller)
        {
        case Controller.Boss:
            // state switch logic for Boss
            vpm = transform.parent.GetComponent <VirusPosManager> ();
            switch (virusState)
            {
            case VirusState.Idle:
            {
                Transform newTarget = tp.PickTarget();
                if (newTarget != null)
                {
                    // we found a new target here, set the target to the new target
                    // and change the state
                    //					Debug.Log ("leaving idle, entering chase");
                    tp.SetNewTarget(newTarget);
                    // entering the chase state
                    virusState = VirusState.Chase;
                }
                break;
            }

            case VirusState.Chase:
            {
                Transform newTarget = tp.PickTarget();
                float     dist      =
                    Vector3.Distance(transform.position, transform.parent.position);

                //if (dist > maxControlDistance) {
                if (newTarget == null || dist > maxControlDistance)
                {
                    // lost the target OR reaching the distance boundary
                    if (dist <= vpm.spreadRadius * 1.2f)
                    {
                        virusState = VirusState.Idle;
                    }
                    else
                    {
                        virusState = VirusState.Return;
                    }
                }
                else
                {
                    // update target
                    tp.SetNewTarget(newTarget);
                }
                break;
            }

            case VirusState.Return:
            {
                Transform newTarget = tp.PickTarget();
                if (newTarget != null)
                {
//						Debug.Log ("leaving return, entering chase");
                    // found new target
                    tp.SetNewTarget(newTarget);
                    // entering the chase state
                    virusState = VirusState.Chase;
                }
                else
                {
                    // set chase target to parent
                    tp.SetParentAsTarget();
                    float dist =
                        Vector3.Distance(transform.position, transform.parent.position);
                    if (dist <= vpm.spreadRadius)
                    {
                        // reached parent object, switch to idle
                        virusState = VirusState.Idle;
                    }
                }
                break;
            }

            default:
                break;
            }
            break;



        case Controller.Hacker:
            // state switch logic for hacker
            switch (virusState)
            {
            case VirusState.Return:
            {
                StopPosReceiver(this.transform);
                tp.SetParentAsTarget();
                float dist =
                    Vector3.Distance(transform.position, transform.parent.position);
                if (dist <= vpm.spreadRadius)
                {
                    // reached parent object, switch to idle
                    virusState = VirusState.Idle;
                }
                break;
            }

            case VirusState.Idle:
            {
                // if the player presses the buttom, release this virus
                // state switch from Idle to Chase is managed in Hacker's script

                break;
            }

            case VirusState.Chase:
            {
                Transform newTarget = tp.PickTarget();
                float     dist      =
                    Vector3.Distance(transform.position, releasePos);
                tp.SetNewTarget(newTarget);
                if (dist > maxControlDistance)
                {
                    HealthSystem hs = GetComponent <HealthSystem> ();
                    if (hs)
                    {
                        hs.InstantDead();
                    }
                }

                break;
            }
            }
            break;

        case Controller.None: {
            StopChase(this.transform);
            break;
        }

        default:
            Debug.LogError("parent obj type must be hacker of boss");
            break;
        }
    }