collision between entities that has anchor is not working properly?

Hi,

I'm new to realitykit and still learning. I'm trying to implement a feature on visionOS that triggers specific logic when the user's head comes into contact with another entity. When two entities are added directly to the realityView, I am able to subscribe to their collision event correctly, but when I add one of the entities to an anchorEntity that is anchored on the user's head, I am unable to receive the collision subscription. , and I found that if an entity declares that it obeys the hasAnchor protocol, it cannot participate in collision detection normally either. Why does this happen? Is this a feature or a bug?

Here is how I subscribe to collision events:

collisionSubscription = content.subscribe(to: CollisionEvents.Began.self, on: nil, componentType: nil) { collisionEvent in
                    print("💥 Collision between \(collisionEvent.entityA.name) and \(collisionEvent.entityB.name)")
}

the following two entity collides fine:

@State private var anotherEntity : Entity = CollisionEntity(model: MeshResource.generateSphere(radius: 1), materials: [SimpleMaterial(color: .white, isMetallic: false)], position: [-2,1,0])

@State private var headEntity : Entity = CollisionEntity(model: MeshResource.generateSphere(radius: 0.5), materials: [SimpleMaterial(color: .yellow, isMetallic: false)], position: [0, -0.35, -3])

but with anchoring, I can't get collision notifications

@State private var anotherEntity : Entity = CollisionEntity(model: MeshResource.generateSphere(radius: 1), materials: [SimpleMaterial(color: .white, isMetallic: false)], position: [-2,1,0])
    
@State private var headEntity : Entity = {
        let headAnchor = AnchorEntity(.head)
        headAnchor.addChild( CollisionEntity(model: MeshResource.generateSphere(radius: 0.5), materials: [SimpleMaterial(color: .yellow, isMetallic: false)], position: [0, -0.35, -3]))
        return headAnchor
}

Any information or suggestion are welcomed, thanks!

Accepted Answer

Hello,

This is a common misunderstanding. AnchorEntity's exist in an independent coordinate space and an independent physics simulation, they cannot collide with anything outside of their own hierarchy.

If you want to "anchor" an Entity to the user's head and have that anchor in the same coordinate space and physics simulation as the rest of your scene, you should use queryDeviceAnchor(atTimestamp:) to get the device pose (i.e. head position and orientation), and then update the transform of your custom head anchor Entity accordingly.

Thank you @DTS Engineer for this answer this sheds some light into an issue I encountered as well.

As a follow up question. Is it somehow possible to have an object which is anchored the floor collide with an object which is anchored to a wall? As an example I apply an impulse to a ball which is anchored to the floor plane. The ball bounces off the floor plane towards a wall. When it hits an object that is anchored to the wall anchor it should trigger a collision event.

Is this possible and if so how?

Thank you so much for your support.

collision between entities that has anchor is not working properly?
 
 
Q