[英]How can I maintain an object's velocity after release in Unity Hololens 2?
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)
.在 Hololens 2 中用手释放球后,我正在寻找投掷而不是保持运动。目前,我正在使用 MRTK IMixedRealityTouchHandler
接口,主要是函数public void OnTouchStarted(HandTrackingInputEventData data)
和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.在 Hololens 2 Emulator 上,当我用手(鼠标)释放球时,它会沿着我指向的大致方向相对缓慢地在空中漂移,这正是我想要的。 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.但是,一旦我构建到 HL2 设备本身,就不会模拟这个动作,并且球在释放后立即停在半空中。 Why is this happening?为什么会这样?
I've tried adding the line rb.AddRelativeForce(Vector3.forward * magnitude, ForceMode.Force);
我尝试添加行rb.AddRelativeForce(Vector3.forward * magnitude, ForceMode.Force);
in OnTouchCompleted
which wasn't successful.在OnTouchCompleted
中没有成功。 How can I maintain the ball's motion after it is released by my hand?手放球后如何保持球的运动?
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.一般来说(我没有看到你的代码的 rest)你可以不断更新相对于最后一帧的速度并最终应用它。
Somewhat like eg (pseudo code)有点像eg(伪代码)
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看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.