I am trying yo make a unity game, and I have a camera controler with mouse + wasd.
I have this code for the camera :
using UnityEngine;
using System.Collections;
public class camera : MonoBehaviour {
public float speedH = 2.0f;
public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
void Start(){
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
public int speed;
// Update is called once per frame
void FixedUpdate()
{
Vector3 Movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
this.transform.position += Movement * speed * Time.deltaTime;
}
void Update () {
float xAxisValue = Input.GetAxis("Horizontal") * Time.deltaTime;
float zAxisValue = Input.GetAxis("Vertical")* Time.deltaTime;
if(Camera.current != null)
{
Camera.current.transform.Translate(new Vector3(xAxisValue, 0.0f, zAxisValue));
}
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
I tried on other project and is working !
Why is this happening. I searched online and saw something about Ghost Keys, But I don’t know what are those.
At the settings at Horizontal are the right keys.
How can I solve this?