Unable to detect collision

In RealityView I have two entities that contain tracking components and collision components, which are used to follow the hand and detect collisions. In the Behaviors component of one of the entities, there is an instruction to execute action through onCollision. However, when I test, they cannot execute action after collisions. Why is this?

Answered by Vision Pro Engineer in 801505022

Hi @lijiaxu

By default, anchors and their children exist in a separate physics simulation. However, you can change this behavior in Swift by getting access to the AnchoringComponent when you load the entity and setting physicsSimulation property to .none:

let anchorComponent = myEntity.components[AnchoringComponent.self]!
anchorComponent.physicsSimulation = .none
myEntity.components.set[anchorComponent]

Here's the official documentation for this property.

Let me know if that helps!

Accepted Answer

Hi @lijiaxu

By default, anchors and their children exist in a separate physics simulation. However, you can change this behavior in Swift by getting access to the AnchoringComponent when you load the entity and setting physicsSimulation property to .none:

let anchorComponent = myEntity.components[AnchoringComponent.self]!
anchorComponent.physicsSimulation = .none
myEntity.components.set[anchorComponent]

Here's the official documentation for this property.

Let me know if that helps!

Hey 👋 I’m trying something similar. I’m using AnchoringComponent with the option .predicted for track finger. I set up the physicsSimulation to none. But I can’t succeed to detect collision. Even if I add PhysicsCollisionComponent and body on the anchor or on a ModelEntity attached to it. Is it normal ?

So it's all good for me.

let configuration = SpatialTrackingSession.Configuration(tracking: [.hand]) let spatialTrackingSession = SpatialTrackingSession.init() _ = await spatialTrackingSession.run(configuration)

was missing.

Another question, I can't get their locations right ? ( Confidentiality )

Unable to detect collision
 
 
Q