Duration: 20 minutes
In a previous tutorial we saw how easy it was to create simple physics objects from tiles and objects, we will now see how easy it is to create more interesting shapes.
Step 1: Getting your map
For this tutorial we are going to use the map we created in the previous tutorial, make sure to remove any physics objects you created for the interesting bit of terrain in the centre as that is what we are going to build today.
Step 2: Creating a circular object
Creating a circular body couldn’t be simpler and can be done on both tiles and objects, this example will show you how to create one on a tile however it is the same process for an object.
First set up your tile properties as before, remembering to include the “HasBody” property. Then simply add a “radius” property as shown below.
You can of course still set all the other physics properties as before I am just showing this now to keep it nice and simple.
You may also wish to set the DrawMode to “hybrid” just so that you can see your new circular body.
Step 3: Creating a polygon object
Circles are great for some things but what is really great is custom shapes, these can help make terrain creation so much simpler. Rather than using trial and error with rotation you can just draw out your terrain like a dot-to-dot picture.
In order to do this you will first want to set up all your point objects, these are simply the corners of your shape. A shape can have no more than 8 points which must be listed in clockwise order. The resulting shape must also be convex-only.
All of these need to have a unique name (unique among them and the whole map), so try naming them something sensible. I have decided to call mine “pointA”, “pointB”, “pointC” and so on.
If you ran your game now nothing interesting would happen (atleast nothing new), that’s because you have nothing telling Lime to build your shape. To do this you first need to select one of your points (it makes sense to select your “first” one) and turn it into a physical object as normal. You then need to give it a property of “points” which will list all the points that you want in the shape.
A lot of you will have noticed that I have created more than 8 points, that is because I will be using a few different shapes to create this terrain object, the first of which is shown below:
I have also set the bodyType to static to make sure it stays where we want it and have added some more tiles above it to see them fall and slide on our terrain.
Now go ahead and create the rest of the required shapes to build the terrain, or download the completed project at the end of the tutorial.
Step 4: Run your game
If you run your game now you will see all your tiles fall onto your new terrain.
Step 5: Even more complex shapes
In a soon to be created tutorial you will see how easy it is to create bodies built up of multiple shapes.