Esempio n. 1
0
 // Camera's gonna vibrate up and down when a player is running.
 // This must appear after player running script for some reason (See PlayerMove to find out)
 private void HandleCameraVibration()
 {
     if (isSprinting)
     {
         if (Mathf.Abs(currentCameraVibrationAngle) >= Mathf.Abs(cameraVibrationLimit))
         {
             cameraVibrationLimit *= -1;
         }
         currentCameraVibrationAngle = TweenLerpUtil.SpeedLerp(currentCameraVibrationAngle, cameraVibrationLimit, cameraVibrationAcceleration);
         Debug.Log(currentCameraVibrationAngle);
         motor.ApplyCamAdditionalRotation(Quaternion.Euler(0, currentCameraVibrationAngle, currentCameraVibrationAngle / 2));
     }
     else
     {
         currentCameraVibrationAngle = 0;
     }
 }
Esempio n. 2
0
    void Update()
    {
        // Add some velocity
        veloctiy -= gravity * Time.deltaTime;

        // Ground check
        if (Physics.CheckSphere(groundCheckTransform.position, groundCheckDistance, groundMask))
        {
            isGrounded = true;
            veloctiy   = 0;
        }

        // Camera Input
        float mouseX = InputHandler.GetViewHorizontalAxis();
        float mouseY = -InputHandler.GetViewVerticalAxis();

        // Aiming
        if (InputHandler.AimKeyHeld())
        {
            aimValue = Mathf.Clamp(aimValue + CommonUtil.GetStepUpdate(), 0, maxAimValue);
        }
        else
        {
            aimValue = Mathf.Clamp(aimValue - CommonUtil.GetStepUpdate(), 0, maxAimValue);
        }
        mainCamera.transform.position = transform.position + mainCamera.transform.rotation * cameraRelative * (1 - maxAimMultiplier * aimValue / maxAimValue);

        // Shoot
        if (InputHandler.FireKeyHeld())
        {
            weaponData.TryShoot(mainCamera.transform);
        }

        // Rotation
        transform.RotateAround(this.transform.position, Vector3.up, mouseX);
        mainCamera.transform.RotateAround(this.transform.position, mainCamera.transform.right, mouseY);

        // Player Input
        float horizontal = InputHandler.GetHorizontalAxis();
        float vertical   = InputHandler.GetVerticalAxis();

        // Player rotate with camera
        transform.Rotate(new Vector3(0, mouseX, 0), Space.Self);

        // Flat movement speed calculation
        float spdLimiter = walkSpeed;

        if (InputHandler.SprintKeyHeld())
        {
            spdLimiter = runningSpeed;
        }
        else if (horizontal == 0 && vertical == 0)
        {
            spdLimiter = 0;
        }
        else if (vertical < 0)
        {
            spdLimiter = -walkSpeed;
        }
        currentSpeed = TweenLerpUtil.SpeedLerp(currentSpeed, spdLimiter, speedAcceleration);

        // === Player Jump ===
        if (InputHandler.JumpKeyDown() && isGrounded)
        {
            isGrounded = false;
            veloctiy  += initialJumpVelocity;
        }
        characterController.Move(veloctiy * Time.deltaTime * this.transform.up);

        // Apply motion
        Vector3 motion = transform.forward * vertical + transform.right * horizontal;

        motion.Normalize();
        motion = motion * Mathf.Abs(currentSpeed) * Time.deltaTime;

        // Apply movement
        characterController.Move(motion);

        // Apply animation
        animator.SetFloat("motionSpeed", currentSpeed);
        animator.SetFloat("jumpSpeed", veloctiy);
        animator.SetBool("isGrounded", isGrounded);
    }
Esempio n. 3
0
 private void Update()
 {
     currentRadius = TweenLerpUtil.SpeedLerp(currentRadius, targetRadius, lerpAcceleration);
 }