Comme vous le voyez ma sourit (liée aux inputs "Hortizontal" et "Vertical") fait bouger la caméra sur les axes X et Y.
Seulement lorsque je bouge ma sourit la caméra bouge sur les 3 axes, une légère rotation en Z intervient malgré moi
J'ai essayé de bouger l'axe X tout seul, c'est parfait. L'axe Y tout seul, aussi. Mais quand les deux bouges l'axe Z est modifié.
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class God : MonoBehaviour {
public float jumpSize = 5;
public float movingSpeed = 5;
public float runSpeed = 20;
public float mousseSensibility = 50;
//Private properties
Vector3 movingMe;
Vector3 rotateMe;
// Update is called once per frame
void Update () {
movingMe = Vector3.zero;
rotateMe = Vector3.zero;
//Calculate moving
if (Input.GetButton("Jump"))
{
movingMe.y = jumpSize;
}
if (Input.GetButton("Crouch"))
{
movingMe.y = -jumpSize;
}
movingMe.x = Input.GetAxis("Horizontal") * movingSpeed;
movingMe.z = Input.GetAxis("Vertical") * movingSpeed;
//Run
if (Input.GetButton("Run"))
{
movingMe.x *= runSpeed;
movingMe.z *= runSpeed;
}
//Calculate rotate
rotateMe.x = -Input.GetAxisRaw("Mouse Y") * mousseSensibility;
rotateMe.y = Input.GetAxisRaw("Mouse X") * mousseSensibility;
//Transform object
transform.Translate(movingMe * Time.deltaTime);
transform.Rotate(rotateMe * Time.deltaTime);
}
}
Code : Tout sélectionner
Quaternion newRotation = transform.localRotation;
newRotation.z = 0;
transform.localRotation = newRotation;