private void Update()
    {
        //Check if the scene has been initialized.
        if (!levelManager.isInitialized)
        {
            return;
        }

        //Check if the game is paused.
        if (!pause.isPaused)
        {
            //Get the input direction and normalize it.
            data.inputDirection = new Vector2(TP_Utilities.GetAxis("Horizontal", keybindings), TP_Utilities.GetAxis("Vertical", keybindings)).normalized;

            //Stop the movement if the player is dead.
            if (player.isDead || anim.animator.applyRootMotion)
            {
                data.inputDirection = Vector2.zero;
            }

            //Move the player in the input direction if we are not dashing.
            if (!states.isDashing)
            {
                Move(data.inputDirection, moveSpeed, false);
            }

            //Rotate the player to mouse point.
            RotateBody();
        }
    }
Esempio n. 2
0
    private void HandleOrbs(bool hasEnoughEnergy)
    {
        if (TP_Utilities.GetAction("SpawnOrbs", KeybindingsProfile.Instance))
        {
            if (hasEnoughEnergy)
            {
                float orbCount = 3;
                float angle    = 0;

                for (int i = 0; i < 3; i++)
                {
                    float posX = Mathf.Cos(angle * Mathf.Deg2Rad);
                    float posZ = Mathf.Sin(angle * Mathf.Deg2Rad);
                    angle += 360 / orbCount;

                    Vector3 offsetDir  = transform.right * posX + transform.forward * posZ;
                    Vector3 spawnPoint = transform.position + offsetDir * 1.3f;

                    Transform orb = Instantiate(orbPrefab, spawnPoint, Quaternion.identity).transform;

                    orb.LookAt(transform.position);
                }
            }
        }
    }
Esempio n. 3
0
    private void HandleEnergyShield(bool hasEnoughEnergy)
    {
        if (TP_Utilities.GetAction("ActivateShield", KeybindingsProfile.Instance))
        {
            if (hasEnoughEnergy)
            {
                if (shieldCooldownTimer == 0)
                {
                    energyShieldObject.SetActive(true);
                    isShielded = true;
                }
            }
        }

        if (TP_Utilities.GetAction("DeactivateShield", KeybindingsProfile.Instance))
        {
            if (isShielded)
            {
                energyRegenTimer    = Time.time + 0.3f;
                shieldCooldownTimer = abilityStats.shieldCooldownTime;
                isShielded          = false;
            }
        }

        if (isShielded)
        {
            energyShieldObject.transform.localScale = Vector3.Lerp(energyShieldObject.transform.localScale, Vector3.one, Time.deltaTime * 10f);

            currentEnergy -= Time.deltaTime * abilityStats.shieldMaintenanceEnergyConsumption;
            currentEnergy  = Mathf.Clamp(currentEnergy, 0f, maxEnergy);

            if (currentEnergy == 0)
            {
                energyRegenTimer    = Time.time + 0.6f;
                shieldCooldownTimer = abilityStats.shieldCooldownTime;
                isShielded          = false;
            }
        }

        else
        {
            energyShieldObject.transform.localScale = Vector3.Lerp(energyShieldObject.transform.localScale, Vector3.one * 0.5f, Time.deltaTime * 10f);
            if (energyShieldObject.transform.localScale.x < 0.58f)
            {
                energyShieldObject.SetActive(false);
            }
        }
    }
    private void Move(Vector2 moveDir, float moveSpeed, bool rawVelocity)
    {
        //Update the movement state.
        states.isMoving = (moveDir.magnitude != 0) ? true : false;

        //Get the target move velocity.
        Vector3 targetVelocity = TP_Utilities.GetTargetMoveVelocity(moveDir, moveSpeed);

        //Interpolate and set the move velocity.
        data.moveVelocity = rawVelocity ? targetVelocity : Vector3.SmoothDamp(data.moveVelocity, targetVelocity, ref moveInterpolationVelocity, 0.05f);

        //Move the player.
        data.controller.Move(data.moveVelocity * Time.deltaTime);

        //Calculate the move magnitude after the player has moved.
        float moveMagnitude = new Vector2(data.controller.velocity.x, data.controller.velocity.z).magnitude / moveSpeed;

        //Animate the player.
        anim.AnimateCharacter(moveDir, moveMagnitude);
    }
Esempio n. 5
0
    private void HandleDash(bool hasEnoughEnergy)
    {
        if (TP_Utilities.GetAction("Dash", KeybindingsProfile.Instance))
        {
            if (hasEnoughEnergy)
            {
                if (dashCooldownTimer == 0)
                {
                    if (!isShielded)
                    {
                        TP_Motor.Instance.BeginDash(abilityStats.dashLength, abilityStats.dashIFrameDuration);
                        currentEnergy -= abilityStats.dashEnergyConsumption;

                        dashCooldownTimer = abilityStats.dashCooldownTime;
                        energyRegenTimer  = Time.time + abilityStats.dashLength + 0.3f;
                    }
                }
            }
        }
    }