简体   繁体   中英

Unity input system issue with using a bluetooth gamepad controlling issue

I am trying to connect up to the new input system specifically with my Nintendo Switch Pro controller (wireless). At runtime the character only moves in a large circle. You can only slightly modify the movement with the controller. What am I doing wrong? I attached photos. Action Map Action Map 2

public class PlayerController : MonoBehaviour {

public float moveSpeed = 5.0f;
public float rotationSpeed = 280.0f;

float horizontal;
float vertical;


// Update is called once per frame
private void Update()
{
    Vector3 moveDirection = Vector3.forward * vertical + Vector3.right * horizontal;

    Vector3 projectedCameraForward = Vector3.ProjectOnPlane(Camera.main.transform.forward, Vector3.up);
    Quaternion rotationToCamera = Quaternion.LookRotation(projectedCameraForward, Vector3.up);


    moveDirection = rotationToCamera * moveDirection;
    Quaternion rotationToMoveDirection = Quaternion.LookRotation(moveDirection, Vector3.up);

    transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToCamera, rotationSpeed * Time.deltaTime);
    transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToMoveDirection, rotationSpeed * Time.deltaTime);

    transform.position += moveDirection * moveSpeed * Time.deltaTime;
}

public void onMoveInput(float horizontal, float vertical)
{
    this.horizontal = horizontal;
    this.vertical = vertical;
    Debug.Log($"Player Input: {vertical}, {horizontal}");

}

}

Hi there it seems that you have created the Action Maps, but you have not used them in your code. I believe to fix this you would need something more like this found on Unity documentation regarding Input Action: "Gamepad.current.leftStick.x.ReadValue();" wherever you have moveDirection on the right-hand side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM