There is a general strategy to run rendering and physics at different scales: scale the parent entity before the physics step, then scale it back after the physics step. Example:
import RealityKit
import Combine
var subscriptions = Set<AnyCancellable>()
func setupPhysicsScaling(scene: RealityKit.Scene, physicsAncestor: Entity) {
let willSimulate = scene.subscribe(to: PhysicsSimulationEvents.WillSimulate.self) { event in
physicsAncestor.setScale([10, 10, 10], relativeTo: nil)
/// do work to prepare for simulation
}
willSimulate.store(in: &subscriptions)
let didSimulate = scene.subscribe(to: PhysicsSimulationEvents.DidSimulate.self) { event in
physicsAncestor.setScale([1, 1, 1], relativeTo: nil)
/// do work to prepare for rendering
}
didSimulate.store(in: &subscriptions)
}
With the setup above, entities that are children of the physics ancestor entity will physically behave as if they were 10 times bigger, but their rendering will remain at nominal scale.
This strategy works but needs careful setup. The key is to reason in terms of per frame update. Before a physics tick, prepare for simulation and maintain coherence. After the physics tick, set the rendering goal.
Topic:
Graphics & Games
SubTopic:
RealityKit
Tags: