1
votes

I'm trying to simulate a soft, bouncy floor (i.e. a trampoline) so that when a significant impulse is given at one point, it causes objects nearby to bounce off in random direction.

However, I'm having difficulties trying to reproduce such behavior in SceneKit.

Here are what I have tried so far:

  1. Call ground.physicsBody!.applyForce(SCNVector3Make(0, -999999, 0), atPosition: pos, impulse: true) on the ground node that has a physics body of type .Kinematic attached to it.
  2. Call ground.physicsBody!.applyForce(SCNVector3Make(0, -999999, 0), atPosition: pos, impulse: true) on the ground node that has a physics body of type .Static attached to it.
  3. Create a SCNPhysicsField.radialGravityField(), attach it to an invisible node, position the node below the floor, and finally give it a negative strength in order to repel objects away.

Both 1 and 2 do not work, no matter how great the given impulse is. Also I verified restitution > 0 on both floor and object. Note that while directly applying impulses to objects works, I'd like to have these impulses (i.e. objects bouncing off a trampoline) automatically calculated by the physics engine in regard to the distance and direction of the previous impulse (i.e. a person jumping on the trampoline) rather than assigning them manually.

Option 3 somewhat gives the effect I want, but it rather applies a continuous force against objects rather than instantaneous.

1
I would test for contact on the trampoline, and then apply a force to all the objects that came in contact with the trampoline. - Pro Blaster

1 Answers

-1
votes

From the documentation;

Static bodies are unaffected by forces and collisions and cannot move. Dynamic bodies are affected by forces and collisions with other body types. Kinematic bodies are not affected by forces or collisions, but by moving them directly you can cause collisions that affect dynamic bodies.

It sounds like a physics body of type .Dynamic is what you are after. A kinematic body would also likely work if you changed its position directly, instead of applying a force to it.