Game Development Reference
Step 5. Play. The flag will flap under the physics of its own weight and
the acceleration values. While the external acceleration is constant,
the random one will add extra boost now and then. This gives an
effect similar to a real flag in a breeze.
Step 6. Beneath the flag add a plane to act as the ground.
Step 7. Next to the flagpole, above the ground, add a sphere. To the
sphere add a rigidbody.
Step 8. Play. Ensure that the sphere falls to the ground.
Step 9. Select the sphere in the Hierarchy and select Component >
Physics > Constant Force to add a force to the sphere. Set the value of
Force for this to the same value as the Cloth's External Acceleration,
for example, ( - 10,0,0).
Step 10. Play. The sphere will now fall but in an arc. When it hits
the ground it will roll off in the direction the constant force is
code in Listing 7.6 .
Listing 7.6 A Scrollbar That Controls the Wind
var cloth: GameObject;
var sphere: GameObject;
var vScrollbarValue : float;
function OnGUI ()
vScrollbarValue = GUI. VerticalScrollbar (
Rect (25, 25, 100, 100),
vScrollbarValue, 0.0, 100.0, 0.0);
Step 12. Attach this code to the Main Camera. Select the Main
Camera and locate the script in the Inspector. Set the values for
cloth to the InteractiveCloth and sphere to the Sphere objects
in the Hierarchy.
Step 13. Play. The scrollbar will control the amount of wind force
on the objects.