SCNNode slows down even with constant velocity set

I have created an App with SceneKit where I have a series of walls (lines made with a SCNShapeNode) and a ball (SCNNode using an SCNSphere). The ball is supposed to continue with a constant speed regardless of where it goes, just changing directions whenever it hits a wall. However, the ball slows down and comes to a stop after a short while. If I start it close to a wall, it bounces off the wall in the correct direction, but then still ends up slowing down to a stop after a short while.

Here is how the balls are created:

let sphere = SCNSphere(radius: 1.0)
var sphereNode1: SCNNode?
let sphereNode1 = SCNNode(geometry: sphere)
let theBody1 = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: sphere))

sphereNode1.worldPosition = SCNVector3(0,20,0)
sphereNode1.physicsBody = theBody1
//sphereNode1.physicsBody!.velocity = SCNVector3(0.0, 2.0, 0.0)
sphereNode1.physicsBody!.applyForce(SCNVector3(0.0, 2.0, 0.0), asImpulse: true)
sphereNode1.physicsBody!.physicsShape = SCNPhysicsShape(geometry: sphere)
sphereNode1.physicsBody!.isAffectedByGravity = false
sphereNode1.physicsBody!.restitution = 1.0
sphereNode1.geometry?.materials = [sphereMaterial]

I tried both giving the ball a velocity and applying a force to it. Both resulted in the above mentioned actions. I can't seem to find anywhere in the documentation that suggests a way to resolve this. I actually did this same thing in the SpriteKit environment and everything worked fine.

Hopefully someone can tell me what I'm missing.

Thanks,

Michael

  • Well, you need to apply some force to the object to keep it going. Think about it.

  • I don't need to keep doing that in SpriteKit. So, what's the difference here? If I turn off Gravity, turn off Friction, then what slows it down. Physics 101: An object in motion remains in motion until acted upon by another force. Shouldn't I be able to have an object that continues to move until acted upon?

Add a Comment