there was simple 6 sided dice before this 12 sided dice as ModelEntity but back then it was working properly for 6 sided dice.enter image description here
let floor = ModelEntity(mesh: .generatePlane(width: 50, depth: 50), materials: [OcclusionMaterial()])
floor.generateCollisionShapes(recursive: false)
floor.components[PhysicsBodyComponent.self] = .init(
massProperties: .default,
mode: .static
)
content.add(floor)
if let diceModel = try? await Entity(named: "d20"),
let dice = diceModel.children.first?.children.first {
dice.scale = [0.1, 0.1, 0.1]
dice.position.y = 0.5
dice.position.z = -1
dice.generateCollisionShapes(recursive: true)
dice.components.set(InputTargetComponent())
dice.components.set(ImageBasedLightReceiverComponent(imageBasedLight: dice))
dice.components.set(GroundingShadowComponent(castsShadow: true))
dice.components[PhysicsBodyComponent.self] = .init(PhysicsBodyComponent(
massProperties: .default,
material: .generate(staticFriction: 0.8, dynamicFriction: 0.5, restitution: 0.1),
mode: .dynamic
))
dice.components[PhysicsBodyComponent]
dice.components[PhysicsMotionComponent.self] = .init()
content.add(dice)
}
}
.gesture(dragGesture)
}