unity 3d first person movement look around code example
Example: unity 3d first person movement look around
public Rigidbody rb;
public float MouseSensitivity;
public float MoveSpeed;
public float JumpForce;
void Start ()
{
//Cursor.visible = false;
}
void Update()
{
//Look around
rb.MoveRotation(rb.rotation * Quaternion.Euler(new Vector3(0, Input.GetAxis("Mouse X") * MouseSensitivity, 0)));
//Move
rb.MovePosition(transform.position + (transform.forward * Input.GetAxis("Vertical") * MoveSpeed) + (transform.right * Input.GetAxis("Horizontal") * MoveSpeed));
//Jump
if (Input.GetKeyDown("space"))
rb.AddForce(transform.up * JumpForce);
}