1
votes

Here is an interesting issue that i have been stuck on for a while and couldn't figure out. I'm playing around in SceneKit (using swift). Whenever or wherever i attempt to put objects with a dynamic physics body into a node hierarchy (i.e add them as a child to another node), the physics bodies separate from the models (sometimes the models just fly away etc). It always works perfectly if I set the bodies to static. Has anyone heard of such thing?

Edit: Sorry if it was slightly unclear previously. Just to add some more information on the issue:

I create the parent node multiple times in a scene. The first time it is created everything is perfect, even objects with dynamic bodies. Now if i create another instance of the parent node further down the z axis for example, the dynamic physics bodies appear to be exactly in the right place but the 3d model not connected to the physics body. Sometimes the model is in sight but nowhere near the physics body or not to be seen at all. If it is visible, as soon as my main game object collides with the dynamic body, the physics body responds as expected but the model disappears instantly. So just to clarify, the dynamic physics body is behaving normally but my imported model that the dynamic body belongs to does not. This is only the case when my object is in a node hierarchy.

As far as setting them to not be affected by gravity, I actually do want them to be affected by it!

Thanks! Sam

1
I think its scene gravity thats its moving your objets, are they moving to the bottom?Mago Nicolas Palacios
How are you creating these nodes?Confused
@Confused I create a scene (for example a .dae or .scn) and I fetch my root node from within. Exactly the same way I've seen everyone else do it.Sam Si Tayeb
I'm not asking how you're getting a reference to the SCNNode, and I have no idea how everyone else does it because nobody much uses SceneKit. I'm asking how do you CREATE your SCNNodes that you're having trouble with?Confused

1 Answers

0
votes

There is a difference between the location of SCNNode.presentation and the node itself. The physics engine will move the presentation. If you set properties on the SCNNode like rotation, position, etc it should reset the node and presentation to match or you could call reset* (not in front of docs right now to get the right name) to reset it manually if needed.

As Mago said, there is probably gravity moving your dynamic bodies. You can turn gravity off from the SceneView's physics engine property, or you can set the physics body's property to not be affected by gravity and see if that fixes it.

Given your description I'm not sure exactly what you observe since the physics body isn't visible just the geometry attached to the SCNNode. Perhaps a little more detail of what you observe that leads to the conclusion that "the physics bodies separate from the models"?