0
\$\begingroup\$

I try to use my xbox controller as input device for a game targeted to run on windows. However the documentation fails to explain how to set it up. E.g. how can I use the right stick from my xbox controller to look around, like in any 3D game? Even such a common task is not documented.

I found a very old wiki entry where the xbox controller is briefly described, I was able to find out that the Y-Axis of the right analog is called 5th axis (Joysticks) and the X-Axis is called 4th axis (Joysticks). I post the images below, in case the link get's dead.

Windows

MAC OS X

Linux

Note: wired controllers only support axises for the d-pad, while the wireless controller only supports buttons for the d-pad, refer to the table above for the wireless controller configuration. Linux

I figured out that the name of a control is responsible for the action which the button, stick, key, pedal etc. does. But it is not documented how the control has to be named for looking around vertically or horizontaly like you can do in an 3D game to look around with the camera by using the right joystick (e.g. witcher 3)

How can I control the camera by using the right joystick?

controler inputs

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

for the axis's set the dead to 0.009 each then for the camera use this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CamerLook : MonoBehaviour {

    public float lookSenitivity = 5;
    public float lookSmoothDamp = 0.1f;
    public float xRotation;
    public float yRotation;
    public float xRotationV;
    public float yRotationV;
    public float currentXRotation;
    public float currentYRotation;
    [HideInInspector]
    public float lStickHorizontal;
    [HideInInspector]
    public float lStickVertical;
    public float lStickV;
    public float lStickH;


    public void Update()
    {
        lStickHorizontal = Input.GetAxis("LeftStickHorizontal");
        lStickVertical = Input.GetAxis("LeftStickVertical");

        lStickH = lStickHorizontal;
        lStickV = lStickVertical;

            xRotation += Input.GetAxis("LeftStickVertical") * lookSenitivity;
            yRotation += Input.GetAxis("LeftStickHorizontal") * lookSenitivity;

            xRotation = Mathf.Clamp(xRotation, -90, 90);

            currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
            currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);

            transform.rotation = Quaternion.Euler(xRotation, yRotation, 0f);

            transform.position = transform.position;
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Gamedev.SE. While we appreciate your answer, we also encourage our answerers to avoid code-only answers. Because explaining the reasons behind the code would benefit the future visitors far greater. \$\endgroup\$ May 22, 2018 at 19:45
-3
\$\begingroup\$

I was able to figure it out.

You have to name the Y-Axis Control Mouse Y and the X-Axis Control Mouse X.

Controler

\$\endgroup\$
1
  • \$\begingroup\$ This is not a universal truth — it just depends on what script you're using to control your look action. I could write a script that looks around based on axes named "achoo" and "gedsundheit" or any other strings provided by the user. Generally I would not advise using a script that expects mouse input and tricking it to use the analog stick instead. These are two different input devices, and to get pleasing game feel you'll want to design specifically for the traits of each one. \$\endgroup\$
    – DMGregory
    Jan 17, 2018 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .