I load an Entity
from Reality Composer and I add a custom CollisionShape
.
These are the steps I follow:
// I get the `.reality` url and I load the model
let rocketSceneUrl = Bundle.main.url(forResource: "Experience",
withExtension: "reality")!
.appending(path: "RocketScene",
directoryHint: .notDirectory)
let rocketScene = try Entity.load(contentsOf: rocketSceneUrl)
// I get the visual bounds of the `boxScene`
let visualBounds = rocketScene.visualBounds(
recursive: true,
relativeTo: self,
excludeInactive: false)
// I generate the custom shape resource.
// I use the y for the height, and half the boundingRadius
let shapeResource = ShapeResource.generateCapsule(
height: bounds.extents.y,
radius: bounds.boundingRadius / 2)
// I create the custom `CollisionComponent`
let collision = CollisionComponent(
shapes: [shapeResource],
mode: .trigger,
filter: .sensor)
// I set the component on the `Entity`
rocketScene.components.set(collision)
// Then I add the `Entity` in the scene.
And this is what I get:
The Entity
with its collision shape appears below the actual content, or conversely the actual content appears above the Entity
and its custom collision shape.
I guess that when RealityKit adds the Entity
on a surface, it compensates by moving the contents in such a way so that it appears to be sitting on the plane, but I may be mistaken.
My question is how do I make the custom collision shape be at the same location where the contents of the Entity
are?