Building a Turning Platform
Building a Turning Platform
articles/Creating Your First Game|Making a Basic Platformer tutorial, you designed a basic obstacle course. In this tutorial, you’ll create a turning platform that makes players jump with perfect timing to land safely on it.
Creating the Base and Platform
The turning platform will spin around and around like a clock hand, but first it needs an anchored “base” or it will fall down into space.
Create the Base
The base can be a simple block, anchored in place.
- Somewhere near another platform (but not too close), create a small block.
- Anchor the new part in space.
Create the Platform
Next, create the platform that will eventually spin around and around. Position this platform so that it sits on top of the base you just created.
Name the Parts
As always, it’s a good idea to name these new objects so they’re easy to find in the Explorer window.
- In the game editor window, select the platform base that you created.
- In the Explorer window, right-click the part’s name and select Rename.
- Enter in PlatformBase.
- Back in the game editor window, find and select the platform part itself. In the Explorer window, rename the part to TurnPlatform.
Attaching the Parts
The basic platform setup is done, but there’s nothing special about it yet. In fact, if you run the game now, the platform will probably just fall off the base and down into space. To prevent that, you need to attach the platform to the base with a constraint.
- To get a better view of things before you add the constraint, move the platform directly up a few studs.
- Select the PlatformBase part in the game editor window, or select it from the Explorer window.
- Zoom in to get a better view of the part. Remember that you can also focus on the part by pressing the F key.
- Make sure that you’re viewing the Model tab.
- In the Constraints section, click the small arrow below Create and select Hinge.
- Move your mouse pointer into the game editor window and hover over the base part. Move your mouse over the part until the attachment (green sphere) is centered on the top surface.
- Click the mouse button to add it.
- Adjust the camera view so that you can see the bottom of the platform (TurnPlatform) located above the base part.
- Carefully move the mouse over the bottom of the platform until the second attachment is positioned directly above the first attachment, then click the mouse button to add it.
Making it Spin
In the Explorer window, find and expand the branches for both PlatformBase and TurnPlatform. Highlighted here are the new constraint objects:
|Attachment0||The first attachment you added, connected to the top of the PlatformBase part.|
|HingeConstraint||The actual hinge constraint.|
|Attachment1||The second attachment you added, connected to the bottom of the TurnPlatform part.|
At this point, the turning platform can spin around the hinge axis but there’s no power to drive it. Fortunately, a hinge can also be made into a motor that turns the platform.
- In the Explorer window, select the HingeConstraint object that attaches the platform to the base.
- In the Properties window, browse all of the properties for the HingeConstraint object. Locate ActuatorType, an important property that makes a basic hinge into a powered motor.
- For this ActuatorType property, click in the area to its right and select Motor.
- Now look at the Motor properties which appear slightly below. To make the platform turn, type in a new value for AngularVelocity. This value determines how fast the motor should turn — in this case, a value of 0.5 should be fine.
- Finally, change the value of MotorMaxTorque to 10000. In your future game design, this value may need to be even higher for a motor to turn a very large, heavy part.
To finish up, move the turning platform back down so that it sits on the PlatformBase part.
Now press the Play button to test. If you did everything right, the turning platform should slowly spin around on the base. The player’s challenge is to jump on the platform at the correct time, then let it carry them around until they can safely jump off to another platform.
Now your game has a dynamic obstacle which challenges players to jump and move with greater skill. Where next? Check out the tutorials below which can help push your game to an even higher level!