Open Search

SceneKit dynamic objects not obeying physics

July 21, 2017 8:40 am
Categorised in: ,
Reading Time: 2 minutes

I recently spent a good few nights struggling with an issue in a SceneKit app I’m toying around with. The scene was rather simple. I created a set of planes programmatically , positioned one after the other creating a 10×10 grid and a gravity field to suck them up like a hoover. After creating a SCNPhysicsField with radial gravity and setting the objects I wanted to be affected by gravity to .dynamic I was getting an effect where the objects kind of exploded kinetically out, rather than taking the radial route caused by the physics object. Once exploded I could see them slowly being drawn to the gravity field so I knew something was working but not what I was expecting.

Sketch of SceneKit radial gravity working correctly vs the kinetic explosion I was getting originally

I must have fiddled with every setting on the physics field and on the plane nodes before I figured out what was happening and nothing I could do, bar setting the objects back to static, allowed them to stay in place until affected correctly by gravity.

So what was the issue?

Well, my noob-ness to 3D is definitely on display here. Turns out, when you scale a node in SceneKit, you don’t scale it’s Collision Masks bounding box. And, after creating my grid of planes master node I was scaling the entire node with the 10×10 grid to fit over and obscure another object.

By not scaling the collision bounding box on the nodes physics settings to the same amount I was scaling the SCNPlanes themselves I was obviously creating a physics effect where these objects could not exist in the same space as each other resulting in a kinetic build up of pressure which just sort of almost instantly exploded. By reducing the collision mask scale, the objects no longer were in contact, and the objects obeyed gravity correctly.

So yeah, physics is hard enough in games and I shouldn’t go trying to build my own universe in the real world as, it turns out, I’m pretty likely to blow everything up.


This joint was penned by @elmarko