claassenApps claassenApps - 4 months ago 18
iOS Question

SKPhysicsBody's .dynamic Property

I have a rectangle node (with rectangular physics body) that I'm performing a repeating SKAction on to move around. I've read that performing actions on objects with physics bodies can cause issues, so if I have the node's physics body set to

.dynamic = false
, can I move it around with an
SKAction
without causing problems? Are there other considerations like setting the
.isAffectedByGravity = false
or does the
.dynamic = false
property override all the other physics properties?

Answer

As explained by the official documents:

The dynamic property controls whether a volume-based body is affected by gravity, friction, collisions with other objects, and forces or impulses you directly apply to the object

Also here:

A Boolean value that indicates whether the physics body is moved by the physics simulation.

The default value is true. If the value is false, the physics body ignores all forces and impulses applied to it. This property is ignored on edge-based bodies; they are automatically static.

Obviusly, if you prepare an SKAction to move to the x an object involved from an impulse that pushes him on the other side or in the same side, you will have an undesirable result in terms of velocity, direction and generally in the behavior caused by additional forces applied by SKAction + the physical forces existing in the physics world. So the answer is: yes, you could cause some problems. It's better to use applyImpulse or velocity or the other methods to control a dynamic object in a context involving the physical laws.

About your last question:

Are there other considerations like setting the .isAffectedByGravity = false or does the .dynamic = false property override all the other physics properties?

I think it's wrong to say the term "override" : when you define affectedByGravity you set a force that affect a physical body, same thing could be about dynamic while the other parameters like mass, density, area, friction .. are properties (characteristics which brings with itself)