Post

Replies

Boosts

Views

Activity

Reply to Drag Gesture in Immersive Spaces with Reality Kit
I realize the code snippet can be better formatted, so here's a better way to look at it struct GearRealityView: View { static var modelEntity = Entity() var body: some View { RealityView { content in if let model = try? await Entity(named: "LandingGear", in: realityKitContentBundle) { GearRealityView.modelEntity = model content.add(model) } } .gesture( DragGesture() .targetedToEntity(GearRealityView.modelEntity) .onChanged({ value in GearRealityView.modelEntity.position = value.convert(value.location3D, from: .local, to: GearRealityView.modelEntity.parent!) }) ) } }
Jun ’24
Reply to Collision Detection after Object Tracking
Additionally, can this even be done? I tracked an object (using the anchoring method and the target being the reference object), then spawn a digital arrow on this tracked object. Now I draw collision boxes around these spawned digital arrows - can I check for collisions between 2 such arrows that are spawned based on 2 different objects being tracked? I read earlier that anchored objects have a different coordinate and physical space, so I'm now questioning if this is the right way to check this. Any suggestions would be very helpful! Thank you
Aug ’24
Reply to Collision Detection after Object Tracking
So this is what I have as my SwiftUI code at the moment import SwiftUI import RealityKit import RealityKitContent struct DualObjectTrackingTest: View { @State private var subs: [EventSubscription] = [] var body: some View { RealityView { content in if let immersiveContentEntity = try? await Entity(named: "SceneFind.usda", in: realityKitContentBundle) { content.add(immersiveContentEntity) print("Collision check started") } } update: { content in //if let cube = content.entities.first?.findEntity(named: "WhiteArrow") as? ModelEntity { let event = content.subscribe(to: CollisionEvents.Began.self) { collisionEvent in print("Collision has occured") } DispatchQueue.main.async { subs.append(event) } } } } How do I change the physics components of the entities that are in the scene that I am loading? I have 2 anchor components added to 2 transforms in my scene - Transform1 and Transform2. Both of these transforms have an anchoring component each with the target being set to a reference object anchor that I am using. I don't see any properties that I can configure inside Reality Composer Pro, so if I need to reach these particular transforms that have the anchoring components, how do I do that from inside my code? It might be a very rudimentary question, but I'm learning swiftUI as I go so some guidance here would be very helpful! Thank you again
Aug ’24
Reply to Collision Detection after Object Tracking
Apologies for the multiple comments, I have now been able to fix the physics simulation issue. I'm now adding collision boxes and physics body components to the 2 entities that I am spawning on my 2 object anchors, and trying to detect a collision between the two when I place the 2 objects on top of each other. Does not seem to be working at the moment. Any advice on what I can do for this? This is the code below that I'm using struct DualObjectTrackingTest: View { @State private var subs: [EventSubscription] = [] var body: some View { RealityView { content in if let immersiveContentEntity = try? await Entity(named: "SceneFind.usda", in: realityKitContentBundle) { content.add(immersiveContentEntity) print("Collision check started") if let Anchor1 = immersiveContentEntity.findEntity(named: "Object1"), var transform1 = Anchor1.components[AnchoringComponent.self], let Anchor2 = immersiveContentEntity.findEntity(named: "Object2"), var transform2 = Anchor2.components[AnchoringComponent.self] { transform1.physicsSimulation = .none transform2.physicsSimulation = .none } } } update: { content in let event = content.subscribe(to: CollisionEvents.Began.self) { collisionEvent in print("Collision HAS OCCURED!") } DispatchQueue.main.async { subs.append(event) } } } } I don't see any console logs indicating that the collision has occurred, even though the entities and their components (collision boxes) should technically be in the same coordinate and physical space..
Aug ’24