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

VR Swing detection

Discussion in 'VR' started by stychu, May 20, 2020.

  1. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Hello folks, for several days I'm struggling with my prototype so now I need some experts to point me the good way. I would like to be able to detect user swing/strike power. How to properly detect how hard user has swung with a controller so I could gather data about position around that swing and build my slash projectile of that. Haven't been able to achieve what I was looking for yet. Maybe someone could help me out.

    I was particularly trying with LineRenderer, trigger button and velocity magnitude of the controller to build a simple line or arc line don't know yet what would bee the best approach. Learning and exploring for now.

    I would like basically to detect a swing not based on any button/trigger click. Purely just the velocity of the controller? Is that a right-thinking?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I've just implemented exactly that for Ilysia. It's a little complicated: I sample the base and tip of the weapon every 0.05 seconds, and keep the last 5 of these. Then I do some math to calculate how "planar" these are (i.e. how much they are all in the same plane), and in the case of an edged weapon, how aligned this swing is with the plane of the blade.

    Then I calculate "swing quality" as simply the velocity (computed as the distance between the current tip position and the oldest sampled tip position) times the planarity. And this is used to trigger the trail and calculate damage.
     
    a436t4ataf likes this.
  3. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Whoa, pretty big project out there! Looking forward to it <3. Thanks for tips, I will try to play around with this information. I Appreciate!
     
    JoeStrout likes this.