Example #1
0
File: comp.cs Project: SolaJr/Dino
    void LateUpdate()
    {
        //*************************************************************************************************************************************************
        // Bone rotation
        if (!shared.IsActive)
        {
            return;
        }

        //Set const varialbes to shared script
        shared.crouch_max = MAXCROUCH;
        shared.ang_t      = ANGT;
        shared.yaw_max    = MAXYAW;
        shared.pitch_max  = MAXPITCH;

        if (shared.lastHit != 0)        //Taking damage animation
        {
            crouch = Mathf.Lerp(crouch, (MAXCROUCH * transform.localScale.x) / 2, 1.0f);
            shared.lastHit--; Head.GetChild(0).transform.rotation *= Quaternion.Euler(shared.lastHit, 0, 0);
        }
        else if (reset)        //Reset
        {
            anm.SetFloat("Turn", Mathf.Lerp(anm.GetFloat("Turn"), 0.0f, ANGT / 3));
            spineX = Mathf.Lerp(spineX, 0.0f, ANGT / 3);
            spineY = Mathf.Lerp(spineY, 0.0f, ANGT / 3);
            crouch = Mathf.Lerp(crouch, 0, ANGT / 3);
        }
        else
        {
            shared.TargetLooking(spineX, spineY, crouch);
            spineX = Mathf.Lerp(spineX, shared.spineX_T, ANGT / 3);
            spineY = Mathf.Lerp(spineY, shared.spineY_T, ANGT / 3);
            crouch = Mathf.Lerp(crouch, shared.crouch_T, ANGT);
        }

        //Save head position befor transformation
        shared.fixedHeadPos = Head.position;

        //Spine rotation
        float spineZ = spineY * spineX / MAXYAW;

        Spine0.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Spine1.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Spine2.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Spine3.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Spine4.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Spine5.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);

        Neck0.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Neck1.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Neck2.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Neck3.transform.rotation *= Quaternion.Euler(-spineY, spineZ, -spineX);
        Head.transform.rotation  *= Quaternion.Euler(-spineY, spineZ, -spineX);

        //Tail rotation
        tailX = Mathf.Lerp(tailX, anm.GetFloat("Turn") * MAXYAW, ANGT / 3);
        Tail0.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail1.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail2.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail3.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail4.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail5.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail6.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail7.transform.rotation *= Quaternion.Euler(0, 0, tailX);
        Tail8.transform.rotation *= Quaternion.Euler(0, 0, tailX);

        //Arms rotation
        Arm1.transform.rotation *= Quaternion.Euler(spineY * 8, 0, 0);
        Arm2.transform.rotation *= Quaternion.Euler(0, spineY * 8, 0);

        //IK feet (require "JP script extension" asset)
        shared.SmallBipedIK(Right_Hips, Right_Leg, Right_Foot0, Right_Foot1, Left_Hips, Left_Leg, Left_Foot0, Left_Foot1);
        //Check for ground layer
        shared.GetGroundAlt(false, crouch);

        //*************************************************************************************************************************************************
        // CPU (require "JP script extension" asset)
        if (shared.AI && shared.Health != 0)
        {
            shared.AICore(1, 2, 3, 4, 5, 6, 7);
        }
        //*************************************************************************************************************************************************
        // Human
        else if (shared.Health != 0)
        {
            shared.GetUserInputs(1, 2, 3, 4, 5, 6, 7);
        }
        //*************************************************************************************************************************************************
        //Dead
        else
        {
            anm.SetBool("Attack", false); anm.SetInteger("Move", 0); anm.SetInteger("Idle", -1);
        }
    }