So if I drag an entity in RealityView I have to disable the PhysicsBodyComponent
to make sure nothing fights dragging the entity around. This makes sense.
When I finish a drag, this closure gets executed:
.gesture(
DragGesture()
.targetedToAnyEntity()
.onChanged { e in
// ...
}
.onEnded { e in
let velocity: CGSize = e.gestureValue.velocity
}
If I now re-add PhysicsBodyComponent
to the component I just dragged, and I make it mode: .dynamic
it will loose all velocity and drop straight down through gravity.
Instead the solution is to apply mode: .kinematic
and also apply a PhysicsMotionComponent
component to the entity. This should retain velocity after letting go of the object.
However, I need to instatiate it with PhysicsMotionComponent(linearVelocity: SIMD3<Float>, angularVelocity: SIMD3<Float>)
.
How can I calculate the linearVelocity
and angularVelocity
when the e.gestureValue.velocity
I get is just a CGSize?
Is there another prop of gestureValue I should be looking at?