Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Fire2"))
        {
            //changing the pitch:
            float mouseX = Input.GetAxis("Mouse X");
            float mouseY = Input.GetAxis("Mouse Y");
            targetYaw   += mouseX * mouseSensitivityX;
            targetPitch += mouseY * mouseSensitivityY;
        }

        float scroll = Input.GetAxisRaw("Mouse ScrollWheel");

        targetDollyDis += scroll * mouseScrollMultiplier;
        targetDollyDis  = Mathf.Clamp(dollyDis, 2.5f, 15);

        dollyDis = Powers_AnimMath.Slide(dollyDis, targetDollyDis, 0.05f);

        cam.transform.localPosition = new Vector3(0, 0, -dollyDis); //EASE

        //changing the rotation to match the pitch variable:
        targetPitch = Mathf.Clamp(targetPitch, -89, 89);

        pitch = Powers_AnimMath.Slide(pitch, targetPitch, 0.05f); //EASE
        yaw   = Powers_AnimMath.Slide(yaw, targetYaw, 0.05f);     //EASE


        transform.rotation = Quaternion.Euler(pitch, yaw, 0);
    }
Beispiel #2
0
    private void BodyAnim()
    {
        if (turretAI.canAttack) //If the turret can attack, it will prepare the attack anims.
        {
            LookAtPlayer();

            //Shrink eye with attacking
            turretEye.transform.localScale = Powers_AnimMath.Slide(turretEye.transform.localScale, new Vector3(0.1f, 0.1f, 0.1f), 0.00001f);
        }
        if (turretAI.reachedPlayer && playerHealth.health != 0) //If the turret has reached the player, it will play the aim animation.
        {
            turretEye.transform.localScale = Powers_AnimMath.Slide(turretEye.transform.localScale, new Vector3(0.2f, 0.2f, 0.2f), 0.00001f);
            turretEye.material             = attackEyeMat;
            LookAtPlayer();

            //If turret aim start is true, then the turret will do a little hop while the wings open.
            if (turretHopWave >= 0 && turretAimAnim)
            {
                turretBody.localPosition = Powers_AnimMath.Slide(turretBody.localPosition, new Vector3(0, -turretHopWave * .075f + 0.5f, 0), 0.001f);
            }

            //Once the little hop is complete, then the aim start var will be disabled, and the turret body position will be reset.
            if (turretHopWave < 0)
            {
                turretBody.localPosition = Powers_AnimMath.Slide(turretBody.localPosition, new Vector3(0, 0.5f, 0), 0.001f);
            }
        }
        else if (turretAI.agent.velocity.magnitude > 0.1f) //If the turret is walking, then it will do the walk bob animation.
        {
            turretEye.material = normEyeMat;

            turretBody.localPosition = Powers_AnimMath.Slide(turretBody.localPosition, new Vector3(0, turretWalkWave2 * .025f + 0.525f, 0), 0.001f);
            turretTop.localRotation  = Powers_AnimMath.Slide(turretTop.localRotation, Quaternion.Euler(0, 0, 0), 0.01f);
        }
    }
    private void Death()
    {
        //Play death SFX on first frame:
        if (!deathSFXplayed)
        {
            playerSource.PlayOneShot(deathSFX);
        }
        deathSFXplayed = true;

        //Disable char controller and scripts affecting animation
        pawn.enabled            = false;
        targetingSystem.enabled = false;
        camOrbit.isDead         = true;

        torsoPoint.enabled = false;
        armPointL.enabled  = false;
        armPointR.enabled  = false;

        //Perform animations
        midsec.localPosition = Powers_AnimMath.Slide(midsec.localPosition, new Vector3(0, -0.95f, 1.2f), 0.008f);
        midsec.localRotation = Powers_AnimMath.Slide(midsec.localRotation, Quaternion.Euler(88, 0, 0), 0.01f);
        torso.localRotation  = Powers_AnimMath.Slide(torso.localRotation, Quaternion.Euler(0, 0, 0), 0.01f);

        armL.localRotation = Powers_AnimMath.Slide(armL.localRotation, Quaternion.Euler(-81, 0, 0), 0.01f);
        armR.localRotation = Powers_AnimMath.Slide(armR.localRotation, Quaternion.Euler(-81, 0, 0), 0.01f);

        legL.localRotation = Powers_AnimMath.Slide(legL.localRotation, Quaternion.Euler(0, 0, 0), 0.01f);
        legR.localRotation = Powers_AnimMath.Slide(legR.localRotation, Quaternion.Euler(0, 0, 0), 0.01f);
    }
    private void TurnTowardsTarget()
    {
        if (playerTargeting && playerTargeting.target && playerTargeting.wantsToTarget)
        {
            Vector3 disToTarget = playerTargeting.target.position - transform.position;

            Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up);

            Vector3    euler1  = transform.localEulerAngles; //Get local angles BEFORE target rotation
            Quaternion prevRot = transform.rotation;         //Save normal rotation
            transform.rotation = targetRotation;             //Set rotation
            Vector3 euler2 = transform.localEulerAngles;     //Get local angles AFTER target rotation

            if (lockRotationX)
            {
                euler2.x = euler1.x;                //Revert X to prev value
            }
            if (lockRotationY)
            {
                euler2.y = euler1.y;                //Revert Y to prev value
            }
            if (lockRotationZ)
            {
                euler2.z = euler1.z;                                                                                   //Revert Z to prev value
            }
            transform.rotation      = prevRot;                                                                         //revert to normal rotation
            transform.localRotation = Powers_AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), 0.02f); //animate rotation
        }
        else
        {
            //figure out bone rotation, no target:
            transform.localRotation = Powers_AnimMath.Slide(transform.localRotation, startingRotation, 0.04f);;
        }
    }
Beispiel #5
0
    void Update()
    {
        age += Time.deltaTime;

        Vector3 offset = Powers_AnimMath.SpotOnCircleXZ(radius, age);

        transform.position = target.position + offset;
    }
Beispiel #6
0
 // Update is called once per frame
 void Update()
 {
     //Update health bar to player's health
     healthbar.rectTransform.sizeDelta = new Vector2((playerHealth.health / 100) * 250, 35);
     //Ease hurt health bar to represent damage taken
     healthbarHurt.rectTransform.sizeDelta = Powers_AnimMath.Slide(healthbarHurt.rectTransform.sizeDelta, new Vector2((playerHealth.health / 100) * 250, 35), 0.01f);
     //Shake healthbar based on how much damage the player has taken
     healthbarHolder.rectTransform.localPosition = new Vector3(healthbarHolderPos.x + (Random.Range(-25, 25) * (healthbar.rectTransform.sizeDelta.x / healthbarHurt.rectTransform.sizeDelta.x - 1)), healthbarHolderPos.y + (Random.Range(-25, 25) * (healthbar.rectTransform.sizeDelta.x / healthbarHurt.rectTransform.sizeDelta.x - 1)), healthbarHolderPos.z);
 }
Beispiel #7
0
    private Vector3 CalcPositionOnCurve(float percent)
    {
        //pC = lerp between pA and handle
        Vector3 c = Powers_AnimMath.Lerp(positionA.position, handle.position, percent, true);
        Vector3 d = Powers_AnimMath.Lerp(handle.position, positionB.position, percent, true);

        Vector3 f = Powers_AnimMath.Lerp(c, d, percent, true);

        return(f);
    }
Beispiel #8
0
    private Vector3 CalcPositionOnCurve(float percent)
    {
        Vector3 c = Powers_AnimMath.Lerp(positionA.position, handleA.position, percent, true);
        Vector3 d = Powers_AnimMath.Lerp(handleB.position, positionB.position, percent, true);
        Vector3 e = Powers_AnimMath.Lerp(handleA.position, handleB.position, percent, true);

        Vector3 f = Powers_AnimMath.Lerp(c, e, percent, true);
        Vector3 g = Powers_AnimMath.Lerp(e, d, percent, true);

        return(Powers_AnimMath.Lerp(f, g, percent, true));
    }
Beispiel #9
0
    private void Death()
    {
        //Countdown until despawn
        turretDeathCountdown -= Time.deltaTime;

        //Play SFX and disable target on first frame.
        if (!initialDeathActionsDone)
        {
            turretAI.turretSource.PlayOneShot(turretAI.turretDieSFX);
            turretAI.GetComponent <Powers_TargetableObject>().enabled = false;
            Instantiate(prefabTurretSmoke, transform.position, transform.rotation);
            turretAI.playerMovementScript.killCount += 1;
        }
        initialDeathActionsDone = true;

        //Turret AI immediately gets deactivated to prevent the turret from moving or shooting.
        turretAI.agent.enabled = false;
        turretAI.enabled       = false;

        //Change and rotate eye to correct position.
        turretEye.material = deadEyeMat;
        turretEye.transform.localRotation = Powers_AnimMath.Slide(turretEye.transform.localRotation, Quaternion.Euler(0, 90, 45), 0.001f);
        turretEye.transform.localScale    = Powers_AnimMath.Slide(turretEye.transform.localScale, Vector3.zero, 0.1f);

        //These animate the turret's body.
        turretBody.localPosition = Powers_AnimMath.Slide(turretBody.localPosition, new Vector3(0, 0.3f, 0), 0.001f);

        turretFrontLegL1.localRotation = Powers_AnimMath.Slide(turretFrontLegL1.localRotation, Quaternion.Euler(0, 0, 0), 0.001f);
        turretFrontLegR1.localRotation = new Quaternion(-turretFrontLegL1.localRotation.x, turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
        turretBackLegL1.localRotation  = new Quaternion(turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
        turretBackLegR1.localRotation  = new Quaternion(-turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);

        turretFrontLegL2.localRotation = Powers_AnimMath.Slide(turretFrontLegL2.localRotation, Quaternion.Euler(60, 60, 0), 0.001f);
        turretFrontLegR2.localRotation = new Quaternion(-turretFrontLegL2.localRotation.x, turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
        turretBackLegL2.localRotation  = new Quaternion(turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
        turretBackLegR2.localRotation  = new Quaternion(-turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);

        turretWingL.localRotation = Powers_AnimMath.Slide(turretWingL.localRotation, Quaternion.Euler(20, 0, 0), 0.001f);
        turretWingR.localRotation = Powers_AnimMath.Slide(turretWingR.localRotation, Quaternion.Euler(30, 0, 0), 0.001f);

        //Shrink body to make destruction less obvious
        transform.localScale = Powers_AnimMath.Slide(transform.localScale, new Vector3(0.75f, 0.75f, 0.75f), 0.5f);

        //If countdown complete, destroy the turret
        if (turretDeathCountdown < 0)
        {
            Destroy(gameObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (playerHealth.health == 0)
        {
            Cursor.lockState      = CursorLockMode.None;
            healthbarHolder.alpha = Powers_AnimMath.Slide(healthbarHolder.alpha, 0, 0.02f);
            deathUI.alpha         = Powers_AnimMath.Slide(deathUI.alpha, 1, 0.02f);

            if (!killcountGotten)
            {
                Powers_PlayerMovement moveScript = playerHealth.GetComponent <Powers_PlayerMovement>();
                killcount.text       = "KILLCOUNT: " + moveScript.killCount;
                killcountShadow.text = "KILLCOUNT: " + moveScript.killCount;
            }
        }
    }
Beispiel #11
0
    private void LookAtPlayer()
    {
        //Rotate the turret top to face the player.
        Vector3 dir = transform.position - turretAI.playerPos.position;

        //Prevent rotation up and down
        dir.y = 0;

        //set the target rotation to the proper value
        targetRot = Quaternion.LookRotation(dir);
        dir       = targetRot.eulerAngles;
        dir       = new Vector3(0, 0, targetRot.eulerAngles.y - transform.eulerAngles.y + 180);
        targetRot = Quaternion.Euler(dir);

        //Rotate the turret top
        turretTop.localRotation = Powers_AnimMath.Slide(turretTop.localRotation, targetRot, 0.01f);
    }
Beispiel #12
0
    private void RotateCamToLookAtTarget()
    {
        if (IsTargeting())
        {
            //if targeting, set rotation to look at target

            Vector3    vToTarget = targetScript.target.position - cam.transform.position;
            Quaternion targetRot = Quaternion.LookRotation(vToTarget, Vector3.up);

            cam.transform.rotation = Powers_AnimMath.Slide(cam.transform.rotation, targetRot, .001f);
        }
        else
        {
            //if NOT targeting, reset rotation
            cam.transform.localRotation = Powers_AnimMath.Slide(cam.transform.localRotation, Quaternion.identity, .001f);
        }
    }
Beispiel #13
0
    private void ShakeCamera()
    {
        if (shakeIntensity < 0)
        {
            shakeIntensity = 0;
        }
        if (shakeIntensity > 0)
        {
            shakeIntensity -= Time.deltaTime * (4 * shakeIntensity);
        }
        else
        {
            return;  //shake intensity is 0, do nothing.
        }
        Quaternion targetRot = Powers_AnimMath.Lerp(Random.rotation, Quaternion.identity, .999f);

        cam.transform.localRotation = Quaternion.Lerp(cam.transform.localRotation, Random.rotation, 0.001f * shakeIntensity);
    }
Beispiel #14
0
    private void LegsAnim()
    {
        //If the turret has reached the player, it will play the aim animation.
        if (turretAI.reachedPlayer && playerHealth.health != 0)
        {
            //These are used to animate the legs during the little hop while the turret aims.
            turretFrontLegL1.localRotation = Powers_AnimMath.Slide(turretFrontLegL1.localRotation, Quaternion.Euler(turretHopWave * 12.5f, turretHopWave * 12.5f, 0), 0.001f);
            turretFrontLegR1.localRotation = new Quaternion(-turretFrontLegL1.localRotation.x, turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
            turretBackLegL1.localRotation  = new Quaternion(turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
            turretBackLegR1.localRotation  = new Quaternion(-turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);

            turretFrontLegL2.localRotation = Powers_AnimMath.Slide(turretFrontLegL2.localRotation, Quaternion.Euler(15 - turretHopWave * 10, 15 - turretHopWave * 10, 0), 0.001f);
            turretFrontLegR2.localRotation = new Quaternion(-turretFrontLegL2.localRotation.x, turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
            turretBackLegL2.localRotation  = new Quaternion(turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
            turretBackLegR2.localRotation  = new Quaternion(-turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);

            if (turretHopWave < 0)
            {
                //This resets the leg positions once the turret is done doing the hop.
                turretFrontLegL1.localRotation = Powers_AnimMath.Slide(turretFrontLegL1.localRotation, Quaternion.identity, 0.01f);
                turretFrontLegR1.localRotation = new Quaternion(-turretFrontLegL1.localRotation.x, turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
                turretBackLegL1.localRotation  = new Quaternion(turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
                turretBackLegR1.localRotation  = new Quaternion(-turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);

                turretFrontLegL2.localRotation = Powers_AnimMath.Slide(turretFrontLegL2.localRotation, Quaternion.Euler(15, 15, 0), 0.01f);
                turretFrontLegR2.localRotation = new Quaternion(-turretFrontLegL2.localRotation.x, turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
                turretBackLegL2.localRotation  = new Quaternion(turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
                turretBackLegR2.localRotation  = new Quaternion(-turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
            }
        }
        else if (turretAI.agent.velocity.magnitude > 0.1f)
        {
            //These are used to animate the legs while walking.
            turretFrontLegL1.localRotation = Powers_AnimMath.Slide(turretFrontLegL1.localRotation, Quaternion.Euler((turretWalkWave2 * -2.5f) - 2.5f, 0, (turretWalkWave1 * -45) - 45), 0.01f);
            turretFrontLegR1.localRotation = new Quaternion(-turretFrontLegL1.localRotation.x, turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
            turretBackLegL1.localRotation  = new Quaternion(turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, -turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);
            turretBackLegR1.localRotation  = new Quaternion(-turretFrontLegL1.localRotation.x, -turretFrontLegL1.localRotation.y, turretFrontLegL1.localRotation.z, turretFrontLegL1.localRotation.w);

            turretFrontLegL2.localRotation = Powers_AnimMath.Slide(turretFrontLegL2.localRotation, Quaternion.Euler(10 - turretWalkWave2 * 5, 10 - turretWalkWave2 * 5, 0), 0.01f);
            turretFrontLegR2.localRotation = new Quaternion(-turretFrontLegL2.localRotation.x, turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
            turretBackLegL2.localRotation  = new Quaternion(turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
            turretBackLegR2.localRotation  = new Quaternion(-turretFrontLegL2.localRotation.x, -turretFrontLegL2.localRotation.y, turretFrontLegL2.localRotation.z, turretFrontLegL2.localRotation.w);
        }
    }
Beispiel #15
0
    void Update()
    {
        //slides the position towards the target:
        transform.position = Powers_AnimMath.Slide(transform.position, target.position, 0.01f);

        //ease cam rotation to look at target:

        //get vector to target:
        Vector3 vectorToTarget = target.position - cam.transform.position;

        //create desired rotation:
        Quaternion targetRotation = Quaternion.LookRotation(vectorToTarget, Vector3.up);

        //set cam to ease towards target rotation:
        if (cam != null)
        {
            cam.transform.rotation = Powers_AnimMath.Slide(cam.transform.rotation, targetRotation, 0.05f);
        }
    }
    private void WiggleLegs()
    {
        float degrees = 45;
        float speed   = 10;

        Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection);
        Vector3 axis          = Vector3.Cross(inputDirLocal, Vector3.up);

        //check  alignment of inputDirLocal against forward vector
        float alignment = Vector3.Dot(inputDirLocal, Vector3.forward);

        alignment = Mathf.Abs(alignment);                             //flips negative numbers
        degrees  *= Powers_AnimMath.Lerp(0.25f, 1f, alignment, true); //decrease degrees when strafing

        float wave = Mathf.Sin(Time.time * speed) * degrees;

        legL.localRotation = Powers_AnimMath.Slide(legL.localRotation, Quaternion.AngleAxis(wave, axis), 0.001f);
        legR.localRotation = Powers_AnimMath.Slide(legR.localRotation, Quaternion.AngleAxis(-wave, axis), 0.001f);
    }
    private void AirLegs()
    {
        if (jumpFirst)
        {
            jumpAnimLegsSwitch = !jumpAnimLegsSwitch;
        }
        jumpFirst = false;

        if (jumpAnimLegsSwitch)
        {
            legL.localRotation = Powers_AnimMath.Slide(legL.localRotation, Quaternion.Euler(30, 0, 0), 0.05f);
            legR.localRotation = Powers_AnimMath.Slide(legR.localRotation, Quaternion.Euler(-30, 0, 0), 0.05f);
        }
        else
        {
            legL.localRotation = Powers_AnimMath.Slide(legL.localRotation, Quaternion.Euler(-30, 0, 0), 0.05f);
            legR.localRotation = Powers_AnimMath.Slide(legR.localRotation, Quaternion.Euler(30, 0, 0), 0.05f);
        }
    }
Beispiel #18
0
    private void ZoomCamera()
    {
        float dis = regDistance;

        if (IsTargeting())
        {
            dis = zoomDistance;
        }

        //check if object behind cam
        RaycastHit hit;

        //do checks to make sure no objects are behind or around the camera
        bool hitObject = Physics.Raycast(transform.position, -transform.forward, out hit, dis, LayerMask.GetMask("Default"));

        if (!hitObject)
        {
            Physics.Raycast(transform.position, -transform.forward + new Vector3(1f, 0, 0), out hit, dis, LayerMask.GetMask("Default"));
        }
        if (!hitObject)
        {
            Physics.Raycast(transform.position, -transform.forward + new Vector3(-1f, 0, 0), out hit, dis, LayerMask.GetMask("Default"));
        }
        if (!hitObject)
        {
            Physics.Raycast(transform.position, -transform.forward + new Vector3(0, 1f, 0), out hit, dis, LayerMask.GetMask("Default"));
        }
        if (!hitObject)
        {
            Physics.Raycast(transform.position, -transform.forward + new Vector3(0, -1f, 0), out hit, dis, LayerMask.GetMask("Default"));
        }

        if (hitObject)
        {
            cam.transform.localPosition = Powers_AnimMath.Slide(cam.transform.localPosition, new Vector3(0, 0, -hit.distance + .5f), 0.000001f);
        }
        else
        {
            cam.transform.localPosition = Powers_AnimMath.Slide(cam.transform.localPosition, new Vector3(0, 0, -dis + .5f), 0.001f);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Fire2"))
        {
            //changing the pitch:
            float mouseX = Input.GetAxis("Mouse X");
            float mouseY = Input.GetAxis("Mouse Y");
            targetYaw   -= mouseX * mouseSensitivityX;
            targetPitch += mouseY * mouseSensitivityY;
        }

        float scroll = Input.GetAxisRaw("Mouse ScrollWheel");

        targetDistance += scroll * mouseScrollMultiplier;
        targetDistance  = Mathf.Clamp(targetDistance, minDistance, maxDistance);

        //If the distance changes, set the target distance to the default distance for the object
        if (lastDistance != distance)
        {
            targetDistance = distance;
        }

        actualDistance = Powers_AnimMath.Slide(actualDistance, targetDistance, 0.01f);

        cam.transform.localPosition = new Vector3(0, 0, -actualDistance); //EASE

        //changing the rotation to match the pitch variable:
        targetPitch = Mathf.Clamp(targetPitch, -89, 89);

        pitch = Powers_AnimMath.Slide(pitch, targetPitch, 0.05f); //EASE
        yaw   = Powers_AnimMath.Slide(yaw, targetYaw, 0.05f);     //EASE

        //Set rotation
        transform.rotation = Quaternion.Euler(pitch, yaw, 0);

        //Slide object towards position
        transform.position = Powers_AnimMath.Slide(transform.position, target.position - transform.forward * distance, .0000000000000001f);

        lastDistance = distance;
    }
    void CalculateOrbit()
    {
        //checks if transform has been added. if not, script can act as a simple rotation script
        if (center != null)
        {
            //Getting the orbit position
            orbitAge += ((Time.deltaTime * timeManager.time) / orbitTime);
            Vector3 offset = Powers_AnimMath.SpotOnCircleXZ(orbitRadius, orbitAge);

            //Getting the orbital tilt, using the center's rotation as a base
            Quaternion orbitTiltFactor = Quaternion.Euler(0, 0, orbitTilt);
            offset = orbitTiltFactor * offset;

            transform.position = center.position + offset;
        }

        //Getting the orbit rotation
        rotationAge          += ((Time.deltaTime * timeManager.time) / rotationTime) * 60;
        transform.eulerAngles = new Vector3(0, rotationAge, transform.rotation.z);

        //Apply the axial tilt using world space
        transform.Rotate(axialTilt, 0, 0, Space.World);
    }
Beispiel #21
0
    private void PlayerOrbitCam()
    {
        float mx = Input.GetAxis("Mouse X");
        float my = Input.GetAxis("Mouse Y");

        yaw   += mx * mouseSensitivityX;
        pitch += my * mouseSensitivityY;

        if (IsTargeting()) //z-targeting:
        {
            pitch = Mathf.Clamp(pitch, -10, 50);
            //find player yaw:
            float playerYaw = moveScript.transform.eulerAngles.y;
            //clamp camera-rig yaw to playerYaw +- 40:
            yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40);
        }
        else //not targeting/ free look:
        {
            pitch = Mathf.Clamp(pitch, -20, 89);
        }


        transform.rotation = Powers_AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f);
    }
Beispiel #22
0
 private void DoTheLerp()
 {
     transform.position = Powers_AnimMath.Lerp(objectStart.transform.position, objectEnd.transform.position, percent, true);
 }
 // Update is called once per frame
 void LateUpdate()
 {
     transform.position = Powers_AnimMath.Lerp(pointA.position, pointB.position, percent, false);
     transform.position = Powers_AnimMath.Lerp(pointA.position, pointB.position, percent, false);
 }
    private void MovePlayer()
    {
        float h = Input.GetAxis("Horizontal"); //Controls strafing
        float v = Input.GetAxis("Vertical");   //Controls forward/backward

        bool isJumpHeld  = Input.GetButton("Jump");
        bool onJumpPress = Input.GetButtonDown("Jump");

        bool isTryingToMove = (h != 0 || v != 0);

        if (isTryingToMove)
        {
            //Turn to face correct direction
            float camYaw = cam.transform.eulerAngles.y;
            transform.rotation = Powers_AnimMath.Slide(transform.rotation, Quaternion.Euler(0, camYaw, 0), .01f);
        }

        inputDirection = (transform.forward * v) + (transform.right * h);
        if (inputDirection.sqrMagnitude > 1)
        {
            inputDirection.Normalize();
        }

        //apply gravity:
        verticalVelocity += gravityMultiplier * Time.deltaTime;

        //adds lateral movement to vertical movement:
        Vector3 moveDelta = inputDirection * walkSpeed + verticalVelocity * Vector3.down;

        //move pawn:
        CollisionFlags flags = pawn.Move(moveDelta * Time.deltaTime);

        if (pawn.isGrounded)
        {
            verticalVelocity = 0; //on ground, zero-out vertical-velocity
            timeLeftGrounded = .1f;
            jumpFirst        = true;
            jumpSFXplayed    = false;
        }

        if (isGrounded)
        {
            if (isJumpHeld)
            {
                //jump!
                verticalVelocity = -jumpImpulse;
                //play random SFX from jump SFX list.
                if (!jumpSFXplayed)
                {
                    playerSource.PlayOneShot(jumpSFX[Random.Range(0, jumpSFX.Count)]);
                }
                jumpSFXplayed = true;
            }
            else if (pawn.velocity.magnitude >= 0.2f)
            {
                //this is used to play footstep SFX when moving forward
                if (isLegLgoingForward && legLxRotLastFrame > 0 && legL.localRotation.x < 0 || !isLegLgoingForward && legLxRotLastFrame < 0 && legL.localRotation.x > 0)
                {
                    if (v >= 0.1f) //Prevents glitchy audio.
                    {
                        playerSource.PlayOneShot(stepSFX[Random.Range(0, stepSFX.Count)]);
                        isLegLgoingForward = !isLegLgoingForward;
                    }
                } //this is used to play footstep SFX when moving sideways
                else if (isLegLgoingRight && legLzRotLastFrame > 0 && legL.localRotation.z < 0 || !isLegLgoingRight && legLzRotLastFrame < 0 && legL.localRotation.z > 0)
                {
                    if (h >= 0.1f) //Prevents glitchy audio.
                    {
                        playerSource.PlayOneShot(stepSFX[Random.Range(0, stepSFX.Count)]);
                        isLegLgoingRight = !isLegLgoingRight;
                    }
                }

                legLxRotLastFrame = legL.localRotation.x;
                legLzRotLastFrame = legL.localRotation.z;
            }
        }
    }
 private void SlideArmsHome()
 {
     armL.localPosition = Powers_AnimMath.Slide(armL.localPosition, startPosArmL, 0.02f);
     armR.localPosition = Powers_AnimMath.Slide(armR.localPosition, startPosArmR, 0.02f);
 }
Beispiel #26
0
    private void WingsAnim()
    {
        if (turretAI.canAttack && playerHealth.health != 0) //If the turret can attack, it will prepare the attack anims.
        {
            if (turretAttackCooldown > 0)                   //Depending on which shot is next from the turret, that appropriate wing will recoil back.
            {
                if (!turretAI.nextShotL && turretAttackCooldown > 0)
                {
                    turretWingL.localRotation = Powers_AnimMath.Slide(turretWingL.localRotation, Quaternion.Euler(70, 25, 0), 0.00001f);
                }
                else
                {
                    turretWingR.localRotation = Powers_AnimMath.Slide(turretWingR.localRotation, Quaternion.Euler(-70, 25, 0), 0.00001f);
                }
            }
            if (turretAttackCooldown <= 0) //Once attack cooldown is complete, reset wing rotations.
            {
                turretWingL.localRotation = Powers_AnimMath.Slide(turretWingL.localRotation, Quaternion.Euler(70, 0, 0), 0.01f);
                turretWingR.localRotation = Powers_AnimMath.Slide(turretWingR.localRotation, Quaternion.Euler(-70, 0, 0), 0.01f);
            }
        }
        if (turretAI.reachedPlayer && playerHealth.health != 0) //If the turret has reached the player, it will play the aim animation.
        {
            //If the ai has switched modes within the last tick, then reset wingAnimOffset.
            if (localReachPlayer != turretAI.reachedPlayer)
            {
                wingAnimOffset = 0.1f;
            }

            turretWingL.localRotation = Powers_AnimMath.Slide(turretWingL.localRotation, Quaternion.Euler(70, 0, 0), 0.001f);
            // If wingAnimOffset reaches 0, begin animaitng turretWingR. This is used to offset it from turretWingL,
            // in order to make the anim slightly asymmetrical and more interesting.
            if (wingAnimOffset <= 0)
            {
                turretWingR.localRotation = Powers_AnimMath.Slide(turretWingR.localRotation, Quaternion.Euler(-70, 0, 0), 0.001f);
            }
            else
            {
                wingAnimOffset -= Time.deltaTime;
            }

            //IMPORTANT!!!! If the anim is complete, then tell the turret AI that it is targeting the player and can attack.
            if (turretWingL.localEulerAngles.x >= 69 && turretWingR.localEulerAngles.x <= 291)
            {
                turretAI.canAttack = true;
            }
            else
            {
                turretAI.canAttack = false;
            }
        }
        else
        {
            //If the ai has switched modes within the last tick, then reset wingAnimOffset.
            if (localReachPlayer != turretAI.reachedPlayer)
            {
                wingAnimOffset = 0.1f;
            }

            turretWingL.localRotation = Powers_AnimMath.Slide(turretWingL.localRotation, Quaternion.Euler(0, 0, 0), 0.001f);
            // If wingAnimOffset reaches 0, begin animaitng turretWingR. This is used to offset it from turretWingL,
            // in order to make the anim slightly asymmetrical and more interesting.
            if (wingAnimOffset <= 0)
            {
                turretWingR.localRotation = Powers_AnimMath.Slide(turretWingR.localRotation, Quaternion.Euler(0, 0, 0), 0.001f);
            }
            else
            {
                wingAnimOffset -= Time.deltaTime;
            }

            //Tell turret that it cannot attack the player now.
            turretAI.canAttack = false;
        }
    }
Beispiel #27
0
    public static float Slide(float current, float target, float percentLeftAfter1Second)
    {
        float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime);

        return(Powers_AnimMath.Lerp(current, target, p, true));
    }
Beispiel #28
0
    public static Vector2 Slide(Vector2 current, Vector2 target, float percentLeftAfter1Second)
    {
        float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime);

        return(Powers_AnimMath.Lerp(current, target, p));
    }
    void Update()
    {
        //Check if player is holding down right click
        if (Input.GetMouseButton(1) && !tutCompleted)
        {
            //Get mouse movement
            camDirection.x -= Input.GetAxis("Mouse Y");
            camDirection.y += Input.GetAxis("Mouse X");

            //If player has moved mouse, complete tutorial
            if (camDirection.magnitude > 5f)
            {
                tutCompleted = true;
            }
        }

        if (tutCompleted)
        {
            //If tut alpha is not 0, lerp it towards 0.
            if (tutAlpha != 0)
            {
                //Set tut alpha to current image alpha
                tutAlpha = tutImage.color.a;

                //Lerp alpha down to 0 if not close, otherwise set to 0
                if (tutAlpha > 0.01f)
                {
                    tutAlpha = Powers_AnimMath.Lerp(tutImage.color.a, 0, 0.05f, false);
                }
                else
                {
                    tutAlpha = 0;
                }

                //Set image color alpha to temp alpha
                tutImage.color = new Color(tutImage.color.r, tutImage.color.g, tutImage.color.b, tutAlpha);
            }

            //If image color alpha is 0 and canvas group alpha is not 1, start work on norm UI alpha.
            else if (tutImage.color.a == 0 && normalUIcanvas.alpha != 1)
            {
                //activate normal ui holder. this was to prevent sfx from playing before the transition starts.
                normalUI.SetActive(true);

                //Set tut alpha to current image alpha
                normAlpha = normalUIcanvas.alpha;

                //Lerp alpha down to 0 if not close, otherwise set to 0
                if (normAlpha < 0.99f)
                {
                    normAlpha = Powers_AnimMath.Lerp(normalUIcanvas.alpha, 1, 0.05f, false);
                }
                else
                {
                    normAlpha = 1;
                }

                //Set image color alpha to temp alpha
                normalUIcanvas.alpha = normAlpha;
            }

            //If normal UI alpha is now 1, the tut is complete. Set canvas group interactable to true and destroy this.
            else if (tutImage.color.a == 0 && normalUIcanvas.alpha == 1)
            {
                normalUIcanvas.interactable = true;
                Destroy(this);
            }
        }
    }