Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resetting Axes not working as expected

Discussion in 'Scripting' started by dichterDichter, Sep 25, 2017.

  1. dichterDichter

    dichterDichter

    Joined:
    Oct 8, 2015
    Posts:
    13
    I have a knob which is attached as joystick to my computer. I can rotate it 360 + Deg.
    I would like to use it in unity, sadly i can only attach it as a joystick axes so it gives me values from -1 / 0 / 1.

    My idea was to reset axes when e.g. -1 is reached and add another -1 so i end up at -2 which would be 180 deg.
    Sadly Input.ResetInputAxes(); is not working at all.

    Is there any
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class joystick : MonoBehaviour {
    6.  
    7.     private float axis = 0.0f;
    8.     private float axisold = 0.0f;
    9.     private float rot = 0.0f;
    10.     private float degree = 90.0f;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.  
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update () {
    19.  
    20.  
    21.         axis = (Input.GetAxisRaw("Horizontal"));
    22.         rot = (axisold + axis) * degree;
    23.         Debug.Log(axis);
    24.  
    25.         transform.eulerAngles = new Vector3(90.0f, 0.0f, rot);
    26.  
    27.         if (axis == -1.0f || axis == 1.0f) {
    28.             axisold = axis;
    29.  
    30.             Input.ResetInputAxes(); // NOT WORKING
    31.  
    32.             axis = 0.0f;
    33.             rot = 0.0f;
    34.         }
    35.     }
    36. }
    way i could use my knob to habe the rotation equivalent?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    So the problem is that this knob can rotate arbitrarily, i.e. it has no limits?

    In that case, it should not be presenting itself to the OS as a joystick. Joysticks don't do that. In fact, hardly anything does that... mice do (with deltas), as do scroll wheels. Perhaps you can get it to present itself as one of them.

    If so, then you could set up a Unity axis of the corresponding type, and get unlimited input from this thing.

    But if it doesn't present itself as one of those, then I think you'd need to dig into some low-level SDK for this device. You might have to contact the manufacturer and see what they suggest. Be sure to mention what OS you want to use it on.
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    What joystick is this? This sounds like a flight controller. There are several flight controllers that have knobs like that.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Oooh, oooh, don't forget Atari VCS pong/combat controllers and also Tempest arcade machines! :)

    Seriously though, if it works, it will probably be by telling you deltas each frame that you are responsible for accumulating, much like the mouse wheel.
     
    JoeStrout likes this.