I’m working on a VisionOS app but I’m a bit stuck on placing anchor entity within an immersive space on another wall with drag gestures.
What I want:
- User enters an ImmersiveSpace
- A photo frame appears before them stick to the wall
- User can then move the frame entity to another vertical wall using DragGesture()The issue I’m having is not able to move the frame entity to another vertical wall with drag gesture.I want to move the entity on the same wall and move to the other vertical wall and restrict to place on the corners.
Here’s my code so far.
@State private var anchor = AnchorEntity()
var body: some View {
RealityView{ content in
let wallAnchor = AnchorEntity(.plane(.vertical, classification: .wall, minimumBounds: SIMD2<Float>(0.1, 0.1)), trackingMode: .once)
let material = UnlitMaterial(color: .clear)
let planeEntity = ModelEntity(mesh: .generatePlane(width: 0.1, height: 0.1), materials: [material])
planeEntity.name = "plane"
async let textEntity = ModelEntity(named: “Photo”)
if let textEntity = try? await textEntity {
planeEntity.addChild(textEntity)
appleWatch = textEntity
wallAnchor.addChild(planeEntity)
anchor = wallAnchor
}
wallAnchor.components.set(InputTargetComponent(allowedInputTypes:.indirect))
wallAnchor.generateCollisionShapes(recursive: true)
content.add(wallAnchor)
} .gesture(
DragGesture()
.onChanged { value in
let startPosition = startPosition ?? anchor.position
self.startPosition = startPosition
let delta = SIMD3<Float>(
Float(value.translation.width) / 1000.0,
0,
Float(value.translation.height) / 1000.0
)
anchor.position = startPosition + delta
}
.onEnded { _ in
startPosition = nil
}
)