Example #1
0
 private void Update()
 {
     hpText.text  = Mathf.CeilToInt(LocalInfo.PlayerHealth).ToString();
     hpText.color = TextGradient.Evaluate(GenericUtilities.ToPercent01(0, 100, LocalInfo.PlayerHealth));
     HealthBar.GetComponent <Image>().color = HpGradient.Evaluate(GenericUtilities.ToPercent01(0, 100, LocalInfo.PlayerHealth));
     hpBarParent.localScale = new Vector3(Mathf.Clamp(LocalInfo.PlayerHealth, 0, 100) / 100, hpBarParent.localScale.y, hpBarParent.localScale.z);
 }
Example #2
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }
        float x = Input.GetAxis("Horizontal");      // X- = A ,X+ = D
        float z = Input.GetAxis("Vertical");        // Z- = S ,Z+ = W

        Vector3 move = transform.right * x + transform.forward * z;

        if (move.magnitude > 1)
        {
            move.Normalize();
        }
        controller.Move(move.normalized * move.magnitude *
                        Lerp(speed * CrouchedPlayerSpeedFactor, speed, GenericUtilities.ToPercent01(CrouchedHeight, UprightHeight, HeightBuffer)) * Time.deltaTime);

        if (InputManager.GetBindDown("Jump") && isGrounded && !LocalInfo.IsPaused)
        {
            velocity.y = Sqrt(jumpForce * -2 * gravity);
            if (anim != null)
            {
                anim.Jump = true;
            }
        }
        controller.Move(velocity * Time.deltaTime);

        if (InputManager.GetBindDown("Crouch"))
        {
            stamina -= StaminaLossPerCrouch;
        }

        if (InputManager.GetBind("Crouch"))
        {
            SetHeightBuffer(Clamp(HeightBuffer - ((CrouchSpeedMultiplier * 5) * Time.deltaTime * stamina), CrouchedHeight, UprightHeight));
            stamina = Clamp01(stamina + (StaminaGainPerSecond / 3) * Time.deltaTime);
        }
        else
        {
            SetHeightBuffer(Clamp(HeightBuffer + ((CrouchSpeedMultiplier * 5) * Time.deltaTime), CrouchedHeight, UprightHeight));
            stamina = Clamp01(stamina + StaminaGainPerSecond * Time.deltaTime);
        }
    }
Example #3
0
    private void FixedUpdate()
    {
        controller.height = HeightBuffer;
        controller.center = new Vector3(0, (HeightBuffer / 2) + .15f, 0);
        if (!isLocalPlayer)
        {
            return;
        }
        if (groundTracer.isGrounded)
        {
            if (velocity.y <= 0)
            {
                velocity.y = Clamp(velocity.y - 5 * Time.fixedDeltaTime, -10, 10);
            }
            isGrounded = true;
        }
        else
        {
            velocity.y += gravity * Time.fixedDeltaTime;
            isGrounded  = false;
        }
        if (anim != null)
        {
            //Planar Movement
            PlanarMovement = ((transform.position - LastLocation) / Time.deltaTime);
            var vecmag = PlanarMovement.magnitude / 10;
            var angle  = Atan2(PlanarMovement.x, PlanarMovement.z) - (transform.rotation.eulerAngles.y * Mathf.Deg2Rad);
            var movDir = new Vector2(Cos(angle), Sin(angle)) * (vecmag > .01 ? vecmag : 0);
            anim.MoveDirection = movDir;
            anim.MoveSpeed     = PlanarMovement.magnitude * (AnimationSpeedMultiplier / 10);
            anim.PlayerAlt     = GenericUtilities.ToPercent01(CrouchedHeight, UprightHeight, HeightBuffer);
            anim.Grounded      = isGrounded;

            LastLocation = transform.position;
        }
    }