A
A
ArtemiyVersh2021-10-22 16:13:07
Unity
ArtemiyVersh, 2021-10-22 16:13:07

Mathf.Clamp doesn't work. What did I do wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera_Controll : MonoBehaviour
{
    
    public Transform Player;
    private float mouseX, mouseY;
    public float sensivity = 200f;
    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    void FixedUpdate()
    {
        mouseX = Input.GetAxis("Mouse X") * sensivity * Time.fixedDeltaTime;
        mouseY = Input.GetAxis("Mouse Y") * sensivity * Time.fixedDeltaTime;

        mouseY = Mathf.Clamp(mouseY, -90, 90);//И чё мы не работаем?
        //Поворот персонажа
        Player.Rotate(mouseX * new Vector3(0, 1, 0));
        transform.Rotate(-mouseY * new Vector3(1, 0, 0));  
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farawa, 2021-11-15
@Farawa

because from GetAxis it’s not some angles that arrive how far the mouse is rotated from some initial position, but dynamically, that is, if you don’t touch the mouse, then the value is 0, if you pull hard, then the max will reach approximately 10. so everything works, you just need to use it correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question