В моем приложении Realitykit у меня есть объекты с .static и .dynamic Physicsbodymodes .
Эти объекты не взаимодействуют, как ожидалось. Таким образом, я написал демонстрационный проект (ниже), который демонстрирует проблему: < /p>
Сцена состоит из доски и 2 сфер выше. Гравитации нет, но сила применяется к правой сфере, которая перемещает ее к левой сфере.
при столкновении, правая сфера останавливается, и левая сфера начинает двигаться, как и ожидалось. PhysicsbodyMode.static , Движение левой сферы останавливается после некоторого смещения, что неправильно.import RealityKit
import SwiftUI
struct ContentView: View {
let sphereRadius: Float = 0.05
let restitution: Float = 1.0
var body: some View {
RealityView { content in
let board = makeBoard()
board.position = [0, 0, -1]
content.add(board)
let sphere1 = makeSphere()
sphere1.position = [0, sphereRadius, -1]
content.add(sphere1)
let sphere2 = makeSphere()
sphere2.position = [0.3, sphereRadius, -1]
content.add(sphere2)
removeGravity(entity: sphere1.parent!)
sphere2.addForce(.init(x: -5, y: 0, z: 0), relativeTo: sphere1)
}
}
func makeBoard() -> ModelEntity {
let mesh = MeshResource.generateBox(width: 1.5, height: 0.02, depth: 1.0)
var material = UnlitMaterial(); material.color.tint = .red
let boardEntity = ModelEntity(mesh: mesh, materials: [material])
boardEntity.generateCollisionShapes(recursive: false)
let physicsMaterial = PhysicsMaterialResource.generate(friction: 0, restitution: 0)
boardEntity.physicsBody = PhysicsBodyComponent(massProperties: .default,
material: physicsMaterial,
mode: .dynamic) // ModelEntity {
let mesh = MeshResource.generateSphere(radius: sphereRadius)
var material = UnlitMaterial(); material.color.tint = .green
let sphereEntity = ModelEntity(mesh: mesh, materials: [material])
sphereEntity.generateCollisionShapes(recursive: false)
let physicsMaterial = PhysicsMaterialResource.generate(friction: 0, restitution: restitution)
sphereEntity.physicsBody = PhysicsBodyComponent(massProperties: .default,
material: physicsMaterial,
mode: .dynamic)
return sphereEntity
}
private func removeGravity(entity: Entity) {
let simulationEntity = PhysicsSimulationComponent.nearestSimulationEntity(for: entity)
var simulation = PhysicsSimulationComponent()
simulation.gravity = .zero
simulationEntity!.components.set(simulation)
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... realitykit