ImpulseAction
An action that applies an impulse to the physics body at its center of mass when played as an animation.
Declaration
struct ImpulseActionOverview
This action requires a CollisionComponent and PhysicsBodyComponent with the mode set to PhysicsBodyMode.dynamic. Without these settings, the impulse has no effect on the entity.
The example below creates an animation which applies an impulse to the entity after five seconds.
// Create an action to apply an impulse, forcing the object to move upwards.
let impulseAction = ImpulseAction(linearImpulse: [0, 1, 0])
// Create a small positive duration value.
let duration: TimeInterval = 1 / 30.0
// Create an animation for the action, which will start playing
// after five seconds.
let impulseAnimation = try AnimationResource
.makeActionAnimation(for: impulseAction,
duration: duration,
delay: 5.0)
// Play the sequence animation that will play the actions.
entity.playAnimation(impulseAnimation)