Page 1 sur 1

Problème avec mon FPS character controller.

Publié : 26 Jan 2020 20:06
par BasisEssence779
Bonjour, je suis en train de créé un FPS character controller mais je ne sais pas comment empêcher la rotation Y d'aller au dessus de 90 ou en dessous de -90.

Code : Tout sélectionner

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

public class MouseLook : MonoBehaviour
{
    // Public variables
    public float MouseSensivity;
    public bool RotateX;
    public bool RotateY;
    // Private variables
    private Transform PlayerBody;
    private float MouseX;
    private float MouseY;

    // Start is called before the first frame update
    void Start()
    {
        PlayerBody = this.transform;
    }

    // Update is called once per frame
    void Update()
    {
        if(RotateX == true)
        {
            MouseX = Input.GetAxis("Mouse X") * Time.deltaTime;
            PlayerBody.Rotate(Vector3.up * MouseSensivity * MouseX);
        }

        if(RotateY == true)
        {
            MouseY = Input.GetAxis("Mouse Y") * Time.deltaTime;
            PlayerBody.Rotate(Vector3.left * MouseSensivity * MouseY);
        }
    }
}
Merci d'avance !

Re: Problème avec mon FPS character controller.

Publié : 26 Jan 2020 20:45
par Aelhan

Re: Problème avec mon FPS character controller.

Publié : 26 Jan 2020 21:37
par Max
Bonsoir,

en complément de la réponse de d'Aelhan, tu peux t'inspirer du script MouseLook.cs fournis dans les StandardAssets, qui propose ce genre de clamp vertical, qui est employé par le FPSController proposé dans ce même StandardAssets.

Re: Problème avec mon FPS character controller.

Publié : 27 Jan 2020 09:09
par BasisEssence779
Merci pour la réponse mais je ne sais pas quelle variable il faut clamper (Il me faut la variable qui défini la rotation).