Make SCNNode fall using gravity?

I have a SceneKit setup and have one sphere that is configured as a dynamic body.

I can run the application and see a sphere fall on the static floor of the body.

What I'm trying to do is set up the scene, so sfere doesn't crash at first.

Then, when the function runs, I want the sfere to be discarded.

What is the correct logic / steps to suddenly make the scene (maybe when a button or something is pressed) lower the sphere?

I have also tried setting the sphere to mass 0 and then setting mass to 100, but it doesn't cause it to fall ...

+3


source to share


3 answers


Mass has no control over how quickly something falls. This is true in the real world, but even more so in simulations that instead use shortcuts to simulate every detail of real world physics. (Unfortunately, iOS devices still lack the processor power to account for the Earth's rotating frame of reference, the van der Waals attraction between your sphere and a body especially close to it, the strong force that holds the trianglesetc.). In SceneKit, gravity is simply constant acceleration in a specific direction.

Setting the mass to zero and switching it to something else interferes with the distinction between static / kinematic and dynamic bodies ... so don't do that.

As @mnuages notes , you can add / delete the physical body from its scope, if you want to be fully affected or not affected by physics.

But what if you want to keep the physical body of the sphere for other reasons, such as allowing other bodies to collide with it even before you start falling? There are several approaches you could use to do this:



Both of these will keep the sphere from moving when something else hits it. If you want the ball to be knocked over without being affected by gravity, your best bet would be to turn off scene gravity for physical fields:

  • Install scene.physicsWorld.gravity

    in SCNVector3Zero

    .
  • Add the SCNPhysicsField

    one created with the constructor linearGravityField

    and set it direction

    and strength

    in get the kind of gravity you want.
  • Place the categoryBitMask

    spheres on both your body and the gravitational field so that the field acts on other bodies, but not on the sphere.

Whichever of these methods you use, you can change them if you want to "rotate gravity on" for the sphere: decrease damping

, reset the, velocityFactor

or change the sphere or gravitational field categoryBitMask

.

+6


source


As of iOS 9, you can set the property isAffectedByGravity

to false

and then flip the value to true

to make the sphere fall: https://developer.apple.com/reference/scenekit/scnphysicsbody/1514738-isaffectedbygravity



+2


source


setting a physical body into a sphere only when you want it to affect gravity should work.

+1


source







All Articles