Unity3d Because my camera is rotating sharply, character even keeps blinking

Asked

Viewed 23 times

1

I made a camera for my game in third person, but when it rotates together with the player, the player sometimes goes away, it seems as if the fps goes down (but it’s just impression). I have done the test to rotate it only on the X axis and it worked, but when it involves X and Y it has this bug. This is my code, there’s some way to soften this camera?

using System.Collections.Generic;
using UnityEngine;

public class cameraLook : MonoBehaviour
{

    public float rotationSpeed = 1;
    float mouseX, mouseY;

    public float zoomMax = 60f;
    public float zoomMin = 40f;
    public float zoomSpeed = 0.1f;
  
    public Transform cam, player;
    
    
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        
    }

    private void LateUpdate()
    {

        CamControl();

    }

    private void Update()
    {
        Zoom();
    }


    void Zoom()
    {
        if (Input.GetMouseButton(1))
        {
            Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, zoomMin, zoomSpeed);
        }
        else
        {
            Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, zoomMax, zoomSpeed);
        }
    }

    void CamControl()
    {
        mouseX += Input.GetAxis("Mouse X") * rotationSpeed;
        mouseY -= Input.GetAxis("Mouse Y") * rotationSpeed; //negativo pois queremos inverter
        mouseY = Mathf.Clamp(mouseY, -35, 35); //limitar campo de visao olhar pra cima e baixo

        transform.LookAt(cam); //foca no alvo

        //rotação do jogador
        cam.rotation = Quaternion.Euler(mouseY, mouseX, 0);
        player.rotation = Quaternion.Euler(0, mouseX, 0);
    }

}
  • would not be the case to decrease the "rotationSpeed"?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.