I fly up when i look and press a movement key. But i dont want to go up. I just want a normal walking script
Heres mine.
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 2.0f;
public Transform playerBody;
public Transform mainCamera;
public CharacterController controller;
// Update is called once per frame
void Update()
{
KeyboardMovement();
}
void KeyboardMovement()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 sidewaysPos = Camera.main.transform.right;
Vector3 forwardPos = Camera.main.transform.forward;
Vector3 move = sidewaysPos * x + forwardPos * z;
transform.Translate(move * moveSpeed * Time.deltaTime);
}
}
,I want a normal movement script. I’ve kinda made my own because the other ones wouldn’t work.
But whenever i look up iand press w (any movement key) I go in the air. I want to fix this but idk how.
Heres my code
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 2.0f;
public Transform playerBody;
public Transform mainCamera;
public CharacterController controller;
// Update is called once per frame
void Update()
{
KeyboardMovement();
}
void KeyboardMovement()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 sidewaysPos = Camera.main.transform.right;
Vector3 forwardPos = Camera.main.transform.forward;
Vector3 move = sidewaysPos * x + forwardPos * z;
transform.Translate(move * moveSpeed * Time.deltaTime);
}
}