-1

I'm looking not so much for a throw as just maintaining motion after a ball is released by the hand in Hololens 2. Currently, I'm using the MRTK IMixedRealityTouchHandler interface, mainly the functions public void OnTouchStarted(HandTrackingInputEventData data) and OnTouchCompleted(HandTrackingInputEventData data).

On the Hololens 2 Emulator, when I release the ball with my hand (mouse), it drifts off in the air in the general direction I was pointing it towards relatively slowly, which is exactly what I want. I achieved this by reducing drag. However, once I build to the HL2 device itself, this motion is not emulated and the ball stops midair immediately after it is released. Why is this happening?

I've tried adding the line rb.AddRelativeForce(Vector3.forward * magnitude, ForceMode.Force); in OnTouchCompleted which wasn't successful. How can I maintain the ball's motion after it is released by my hand?

thean
  • 97
  • 9
  • As any known issues will be fixed in the latest version, have you tried on the latest Unity 2020.3 LTS version? Have you tried OpenXR plugin? If the behavior is the same, please provide more information about your developing environment, such as the Version number of your Unity & MRTK, the Build Setting of Unity, and the HoloLens System version? – Hernando - MSFT Feb 17 '22 at 08:16
  • @Hernando-MSFT I'm using Unity 2020.3.13f1, MRTK 2.7.30. I'm using the HoloLens 2 Emulator (10.0.19041.1113), with the Hololens Device OS Build being 20348.1447. Unity build settings are set to ARM64 – thean Feb 18 '22 at 17:25

1 Answers1

0

In general (I don't see the rest of your code) you can keep updating the velocity relative to the last frame and finally apply it.

Somewhat like e.g. (pseudo code)

private Vector3 velocity;

void BeginDrag()
{
    rb.isKinematic = true;
    rb.velocity = Vector3.zero;
    lastFramePos = rb.position;
}

void WhileDrag(Vector3 position)
{
    velocity = position -rb.position;
    rb.position = position;
}

void EndDrag()
{
    rb.isKinematic = false;
    rb.velocity = velocity;
}

or actually even easier and probably more accurate you can directly use the

public void OnTouchCompleted(HandTrackingInputEventData data)
{
    rb.velocity = data.Controller.Velocity;
}

See

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Thanks! I tried both of these out, and while they work great in the Hololens 2 Emulator, the ball still stops completely in Hololens 2 device itself. I don't think its an error in script but rather something to do with the differences between emulator and device? Not sure what's going on tbh. – thean Feb 14 '22 at 21:15