Sorry about the bad resolution
Hi everyone,
I have a problem when using the gamepad on my computer it switches randomly in and out of the gamepad control scheme I have no idea why its doing it and I’ve never had issues like this before (I don’t think) so if anyone knows how to fix this please help
Heres the Input Actions Manager: Link
Heres my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;
public class PlayerController : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private Vector2 playerMoveInput, playerLookInput;
[SerializeField] private float speed, startingPos;
public float pitch, roll;
// Start is called before the first frame update
void Awake()
{
_rb = GetComponent<Rigidbody>();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void FixedUpdate()
{
_rb.AddForce(
(playerMoveInput.x + playerMoveInput.y) * speed * _rb.mass * Time.deltaTime,
0,
(playerMoveInput.y - playerMoveInput.x) * speed * _rb.mass * Time.deltaTime,
ForceMode.Impulse);
pitch = (transform.position.x + playerLookInput.x) - transform.position.x;
roll = (transform.position.y + playerLookInput.y) - transform.position.y;
// Wrap the pitch and roll values back to the range [-180, 180]
// Makes sure that the values dont get too large when the object rotates
pitch = Mathf.Repeat(pitch + 180, 360) - 180;
roll = Mathf.Repeat(-roll + 180, 360) - 180;
// Makes it so that these values are always in the opposite direction of the rotation
roll *= -1;
// Prevents some shitty error
if (pitch != 0 || roll != 0)
{
Quaternion rot = Quaternion.LookRotation(new Vector3(-pitch, 0, -roll), Vector3.up);
rot = Quaternion.Euler(0, startingPos, 0) * rot;
transform.rotation = Quaternion.Lerp(transform.rotation, rot, 0.1f);
}
}
public void Move(InputAction.CallbackContext context)
{
playerMoveInput = context.ReadValue<Vector2>();
}
public void Look(InputAction.CallbackContext context)
{
playerLookInput = context.ReadValue<Vector2>();
}
}