Zum Beispiel:
Code: Select all
var body = PhysicsBodyComponent(
shapes: [shape],
density: 1,
material: .generate(
friction: 0.8,
restitution: 0.8),
mode: mode)
// here
body.linearDamping = 2.0
Ich habe versucht, PhysicsMotionComponent zu verwenden und seine lineare Geschwindigkeit in Aktualisierungsaufrufen manuell anzupassen:
Code: Select all
struct RLPhysicsDampingSystem: System {
func update(context: SceneUpdateContext) {
// ...
// This is always nil, despite entities are moving
guard var motion = entity.getComponent(PhysicsMotionComponent.self),
else { continue }
var linVel = motion.linearVelocity
// Damping formula: e^(-d * dt)
let linDamping = exp(-damping.horizontalLinearDrag * Float(delta))
linVel.x *= linDamping
linVel.z *= linDamping
motion.linearVelocity = linVel
entity.components.set(motion)
Mobile version