Search Unity

2D vector composition with buttons and axis

Discussion in 'Input System' started by chakshoorai, Sep 16, 2019.

  1. chakshoorai

    chakshoorai

    Joined:
    Aug 5, 2019
    Posts:
    3
    Is it possible to create a 2D Vector composite where one component is mapped to a positive/negative button and the other is mapped to an axis?

    The use case would be to have the x component of the vector mapped by A and D where A is -1 and D is 1.
    The y component of the vector would be Mouse Delta/Y.
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    No, this is not currently possible. Use two separate axis controls for this.
     
  3. chakshoorai

    chakshoorai

    Joined:
    Aug 5, 2019
    Posts:
    3
    Ok, thanks. I can work around this for my purposes but are there plans to have something like this in the future?
     
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Not atm. While I can see the use, I'm not convinced that this is common enough to expose and maintain some API for this? You could of course also build such a composite yourself: Writing custom Composites
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Thinking about this, seems like something that Vector2Composite should allow you to do out of the box. ATM it treats up/down/left/right as buttons and, other than making sure they do cross the button press threshold, it throws away their values.

    This could easily turned into an optional behavior where instead it will use the values read from up/down/left/right as the components of the resulting vector. If both controls on a given axis are actuated, it would simply treat them as pulling the opposite way and use the midpoint of the two as the resulting value.

    This way you could easily bind A and D on left and right and mouse delta up and down on up and down and probably get what you're looking for here.
     
  6. chakshoorai

    chakshoorai

    Joined:
    Aug 5, 2019
    Posts:
    3
    Sounds like a clever solution. Unfortunately, I don't know enough about the inner workings of the system to make that happen. I've just gone with the lazy approach of splitting up into 2 axis.