I need some help in understanding how forces are applied to physics bodies in SceneKit.
My SCNSphere is defined as follows:
let startsphere = SCNSphere(radius: CGFloat(0.2))
startsphere.firstMaterial?.diffuse.contents = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.3)
let startsphereNode = SCNNode(geometry: startsphere)
startsphereNode.position = SCNVector3(0.0, 1.0, 0.0) // center of playfield, 1m height
startsphereNode.physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
startsphereNode.physicsBody?.isAffectedByGravity = false
startsphereNode.physicsBody?.friction = 0.0
startsphereNode.physicsBody?.rollingFriction = 0.0
startsphereNode.physicsBody?.damping = 0.0
startsphereNode.physicsBody?.restitution = 1.0
This sphere is enclosed in a box made up of 6 planes where the sphere shall bounce off from. The collision masks and are set so that the sphere bounces off these walls and I can observe that when I move the sphere with an SCNAction.
Now I apply a force like this:
startsphereNode.physicsBody?.applyForce(SCNVector3(50000,0,0), at: startsphereNode.position, asImpulse: false)
// or like this
startsphereNode.physicsBody?.velocity = SCNVector3(200,0,0)
I observe the behavior of the sphere in the scene. When the force is applied (or the velocity is set) the sphere instantaneously jumps far outside the box to the right and then slowly moves back (in leftward direction ) to its previously set position (0,1,0). I can see it moving through the wall.
Now my questions:
Why does it jump (und not move) to the right ? I have played around with the impulse and velocity magnitudes, but always the same.
Why is it moving back to it's original position once the force is applied ?
Why does it not bounce off the right wall ? I see it "shot through" the wall.
The behavior I would like to achieve is after application of the force the sphere bouncing inside my box according to the physics set up.
Any thoughts ? Thanks.