Search Unity

Question Track how hard GameObject button is pressed

Discussion in 'XR Interaction Toolkit and Input' started by Vals9, Feb 7, 2023.

  1. Vals9

    Vals9

    Joined:
    May 22, 2019
    Posts:
    4
    I am trying to create CPR simulation for Quest 2 wand looking for a way to track how hard user is pressing on object (in this case it's chest area). To make my life easier, I was thinking of creating button that can be pressed and hide it inside human's 3d model instead of creating complex rig for model (there will probably still be some basic compression/decompression on 3d model to make it look more realistic).
    Basically, I want to do something like this

    The caveat is that I need to track value of how hard button is pressed by user (game object, not button on controller), let's say from 0 to 100, rather than just pressed/not pressed state and I'm looking for some pointers.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,041
    Get the Velocity from the controllers?
    You can't really use force when pushing in the air, so velocity/speed or acceleration will probably be used
     
    VRDave_Unity likes this.
  3. Vals9

    Vals9

    Joined:
    May 22, 2019
    Posts:
    4
    For anybody trying to achieve the same, here's basically what I did. I used button displacement value (newPosition in script) as value for my simulated pressure meter. Then in my pressure meter bar (I used simple progress bar), I inverted values.


    float pressureAmount = Mathf.InverseLerp(buttonTopPosition, buttonDownPosition, hb.pressureAmount);
    current = Mathf.Lerp(minimum, maximum, pressureAmount);

    In my case,
    buttonTopPosition = 8.1603f
    buttonDownPosition = 8.128f
    for button positions and
    minimum = 0
    maximum = 100
    for progress bar
    Refer to this post to get a better understanding of code above.


    Basically, when button goes down, value in progress bar goes up and vice versa.
     
  4. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    257
    XRI 2.3 includes a new poke interaction filter that can achieve this. We have a new hands sample scene coming that will show how to set this up with the new poke interactor, whether you're using hands or controllers. Hopefully that helps! The new sample should be available soon.
     
    Vals9 and Niter88 like this.