I’ve encountered an issue with switching between controller and k&m. I’m making a top down game and for some reason as soon as i switch to controller, Player.Look is stuck at a seemingly random value and moving the right stick does absolutely nothing. When i’m switching to controller, i activate an image of a reticle and move it a certain amount away from the middle of the screen in the direction of the Look value, when i switch to k&m, i disable the image and use the cursor. Here’s the code for the switching, tied to the controls changed event in player input.
public void OnControlSchemeChange()
{
if(playerInput.currentControlScheme == "Keyboard&Mouse")
{
Cursor.visible = true;
virtualCursorTransform.gameObject.SetActive(false);
keyboardActive = true;
}
else
{
Cursor.visible = false;
virtualCursorTransform.gameObject.SetActive(true);
keyboardActive = false;
}
Debug.Log($"Keyboard active: {keyboardActive}");
}
Also for some unknowable reason the right stick starts working as intended… if i click anywhere in the editor. The character snap-turns southwest and if i start using my controller, the right stick works as intended.
Here’s the code for the update that moves the virtual cursor around:
private void Update()
{
if (!keyboardActive)
{
Vector2 lookDirection = CharacterScript.inputSystem.Player.Look.ReadValue<Vector2>().normalized;
Debug.Log($"Controller moves the reticle! Look direction: {lookDirection}");
if (lookDirection != Vector2.zero)
{
if(virtualCursorTransform.gameObject.activeSelf==false)
virtualCursorTransform.gameObject.SetActive(true);
Vector2 aimPoint = new Vector2(middleOfCanvasTransform.position.x + lookDirection.x * cursorDistance, middleOfCanvasTransform.position.y+lookDirection.y*cursorDistance);
virtualCursorTransform.position = aimPoint;
}
if (lookDirection == Vector2.zero)
{
virtualCursorTransform.gameObject.SetActive(false);
}
}
}
What causes this? How can i fix it? I’m THIS close to getting the control scheme switching to work as intended :<