Game Development Reference
In-Depth Information
This is a side-effect of combining actions with physics. More precisely, actions affecting a
node's position or rotation properties should not be used on dynamic bodies. They over-
ride the physics properties for position and rotation, while ignoring the body's velocity, at
least temporarily.
In some cases, move and rotate actions seem to move but the resulting collision behavior
won't be what you'd expect, because the movement imposed by the action is not reflected
by the node's internal state or conflicts with it. For instance, a move action won't stop be-
cause there's a collision in the way; instead, it'll continue to move the node through the
collision step by step and the physics engine will try its best to resolve the situation every
frame, causing all sorts of issues.
Moving a physics-enabled node, therefore, should be done exclusively by applying forces
to the node, or by using joints. An exception to this rule are static bodies. Those you can
actually animate using move and rotate actions—and even the SpriteBuilder
Timeline—and they'll show correct physics behavior. I'll say more on this topic in chapter
5 : Timelines and Triggers .
There are also purely visual or functional actions like tinting the node's color or running a
block. Those actions can still be used on a node with a physics body indiscriminately.
Note If you are curious as to why move and rotate actions cannot be combined
with physics, consider a leaf blowing in the wind. Normally, a light object such
as a leaf will stop when it hits any other object. The leaf has a low mass, so it
will not exert noticeable force on colliding bodies. However, if you told the leaf
to move on a straight line from A to B with a move action, this would keep it
going into and over heavier or impenetrable objects. What should the correct
physics behavior be in this case?
Should the leaf eventually topple over the wall it hits? Should it be allowed to
penetrate objects to get to the intended location? Or should it stop at the wall
but stick to it because it tries to keep going to its destination until it arrives
there? Or until the action ends, which means the leaf may never reach its destin-
ation?
There is not one right way to solve this. In fact, all of the possible workarounds
are wrong. Some just seem more correct than others when considering only a
narrow set of conditions or a specific set of expectations, but there is no gener-
ally acceptable solution.
Search WWH ::




Custom Search