Game Development Reference
In-Depth Information
Creating a Rope
How to create a physics rope is a frequently asked question, yet the solution is not nearly
as complex as you might imagine. In fact, if you observed the behavior of the chain, you
may have noticed that it isn't too far from how a physics-simulated rope should behave.
Turning the Chain into a Rope
In fact, you're just going to modify the chain to make a rope. To do so, create a duplicate
of
Chain.ccb
and rename it to
Rope.ccb
.
Note
If SpriteBuilder has no duplication functionality yet, you can make a
copy with Finder. Locate the project's .spritebuilder folder and browse into the
SpriteBuilder Resources/Prefabs folder in order to make a duplicate of the
Chain.ccb
. You should then rename the duplicate to
Rope.ccb
. In SpriteBuild-
er's
File View
, the
Rope.ccb
should automatically appear in the
Prefabs
folder.
Open the
Rope.ccb
. Several modifications to the chain are necessary to turn it into a rope.
First, select all the
chain2
sprites, and on the
Item Properties
tab, change their
Sprite
frame
to
SpriteSheets/GameElements/chainball_chain1.png
in order to replace the
8-shaped chain elements with the l-shaped ones. This step is added only to improve the
visual appearance of the rope.
Because changing the sprite frames also changes the locations of the pivot joints, you
should select the joints that are offset from the rope and change their anchor to 6.5x4 so
that all pivot joints are on the rope and spaced evenly. Also, if you switch to the
Item
Physics
tab and select the former
chain2
sprites, you'll notice their collision shape is too
big for the image. So you should also edit the collision shape to more closely match the
chain1
images that you are using as rope segments.
Also, change the
Scale
property of the ball to
0.5x0.5
to make it smaller. Change its Y po-
sition to -156 to make it connect with the rope. And, on the
Item Physics
tab, change its
density to
0.15
to make the ball lighter. These new settings will reduce stress on the rope
and allow it to swing more easily.
The former chain segments will feel more like a rope if you tweak the joints so that the
spring is enabled and the angle limit is smaller than before. Perform the following steps
Search WWH ::
Custom Search