Hello,
I wanted to move a certain object by clicking the new position. Is there a way I can do that in RealityKit. The behavior allows moveBy and moveTo. I want to pass the new coordinates of the object by another touch.
Assuming you've set up a UITapGestureRecognizer for your ARView, and have a function that starts like this:
@objcfunc handleTap(_ sender: UITapGestureRecognizer? = nil) {
Get the CGPoint of that touch:
guard let touchInView = sender?.location(in: self.arView) else {
return
}
Perform a raycast at that CGPoint:
if let result = arView.raycast(
from: touchInView,
allowing: .existingPlaneGeometry, alignment: .horizontal
).first {
print(result.worldTransform)
// worldTransform is of type simd_float4x4
}
From there, use this 4x4 matrix to position your entity at the touch location in the scene using moveTo.