-
Notifications
You must be signed in to change notification settings - Fork 3
Custom Level Grounds
This guide will provide steps for making a very simple level as a sector inside an existing level (Greece).
Note that a level consists of two types of models:
- the rendered geometry which is used to display the level.
- the collision model, the "Grounds", which is a simplified model that is used for collision with the heroes, enemies. Basically it defines where players and other entities in the game can stand and walk on.
This way, the rendered model can have as many details without impacting performance on collision. It also makes the collision more stable and less buggy.
Here we will mainly focus on the Grounds (the collision model). Making the rendered geometry is much more straightforward.
- You have some basic knowledge on 3D modelling.
Before we start making our own levels, let's first take a look at some existing level from the game and learn how the developers made them.
It is possible to visualize the Grounds in the editor. For this, load a level, then in the Main window, tick the Grounds checkbox. In the following screenshot are the Grounds from Greece:
Click on any Ground to select it, which will mark it as green. Notice how the grounds are splitted into multiple ones.
When unselected, the gray faces are the triangles where you can stand and walk, and the blue faces are walls, which prevent the heroes to pass through. They often extend vertically from the outer bounds of the ground triangles.
You can also see the Grounds' bounding boxes by ticking the Ground bounds checkbox. These bounding boxes are used to check if the hero is inside the ground before checking collisions with every triangle, which can save a lot of processing time.
In the toolbar, click the Grounds icon (in the General group) to open the Grounds window. At the left is a list of all grounds, grouped by sector, and at the right are the properties of the selected (green) ground.
The properties of a ground define what happens when you stand on it. The following flags apply to XXL 1:
- Walkable means the hero can walk on it (it is enabled). This should always be set.
- Bouncing means it will make the hero jump like a trampoline.
- Slide makes it sliding.
- Hurt makes the hero lose health (like fire).
- Death instantly kills the hero (like a death trap).
- Water gives a water plane whose height is defined in the Parameter value. If deep enough, the hero can swim.
You can try changing some of the flags, save, then test the level and see what happens next :)
Note that the properties are per Ground, not per triangle. That means, when designing grounds, you will always need to separate triangles from a ground to a new one if you would like to apply new properties to them without affecting the entire ground.
To make the Grounds, you can use any 3D modelling software, such as Blender, to model the grounds, which you will later export in OBJ format and import it to the editor.
Note that in Kal, the Grounds consist of:
- vertices
- triangles formed from the vertices, defining where the hero can walk on
- walls: quads formed from two vertices for the base then extended vertically, prevents heroes to pass through
- infinite walls: same as (finite) walls but extended vertically infinitely
Due to this, there are constraints in how you can make walls in Kal:
- they have to be quads,
- they have to be exactly vertical, meaning they have to be parallel to the height axis. If not, the game will fail to collide entities with it,
- the edges from bottom to top are also parallel to the height axis (e.g. you take a vertex from the base and you have to extrude it on the height axis).
Here are some figures illustrating the constraints:
The walls vertical edges need to be parallel to the height (Y) axis. Note that the vertical edges can still have different lengths.
Each vertical edge are either both extended from the base to the top, or both from the base to the bottom, but not one to the top and the other to the bottom and vice versa:
All the contraints on the wall kind of limit the way you construct them. However, it is possible to be creative and use tricks to get around them. For example, to get a wall shaped as a right triangle, you can approximate it with a quad that has a very small vertical edge, as shown in the following figure:
As the goal of this guide is NOT to explain Blender and 3D modelling, which are already complicated to explain on their own and there are tons of tutorials on the Internet which can explain better than I can, what I will do is simply provide a simple example OBJ file that contains simple grounds, and give some commentary:
Here are some Grounds to a simple sector:
You can even watch a video of that sector in action on YouTube:
The grounds model in .OBJ format can be downloaded here: colltest.obj
The OBJ actually contains multiple objects. If you import the OBJ in Blender, you can see the list of objects:
Every object in the OBJ corresponds to a separate Grounds object in the game. Every object is also given a unique name. This is important as that lets the editor know if an object is already imported, and if yes it will replace the ground instead of duplicating it, and you also keep the behaviour flags without you having to put them back. So when designing your grounds, try giving your objects unique names.
You can also see that there are only quads for the walls, and the rest is triangles. The walls also are precisely vertical, and vertical edges are parallel to the height axis (Y in game, Z in Blender).
Speaking of axis, in the game, Y is the height axis, but in Blender it is the Z axis, hence when exporting to OBJ be sure that you set the export option to swap the Y and Z axis.
Another thing to notice are the floating platforms. You can see that one floating platform actually has two grounds:
- one for the platform's top,
- one for the platform's bottom and the four walls.
The reason is that if you have ground triangles that are one above the other (same XZ coordinates but different Y), you have to separate them in different objects. Otherwise the game will only recognize one triangle and collide with it.
Finally, it is time to import the grounds. Here we will try to add the grounds into a new sector of an existing level.
- Open the editor and load a level (Greece).
- Open the Level properties window, then click the Add sector button. This will add a new sector to the level.
- Open the Grounds window.
- On the left side, you should see a new sector that is empty (Sector 7 in case of Greece). Click its Import button and open the OBJ file.
- At the top of the Grounds window, click the Make Scene geometry from Grounds button. This will create a rendered scene geometry out of the imported Grounds, letting you see the Grounds in-game (as normally they are invisible). So you can test and see your custom sector before you start making a rendered model of your sector.
We will also change the spawning positions of the heroes so that the level will start in your new sector:
- Open the Level properties window.
- Open the Level Start header.
- Click somewhere in your sector's geometry/grounds to set the cursor there, then click the "Teleport heroes to cursor and update start positions" button. You should now see Asterix, Obelix and Dogmatix at the cursor.
- Set the Initial sector value to the new sector you created. In the case of Greece, a new sector would be sector number 7.
- Save and test the level!
Notes:
- Be sure walls are quads, and meets all constraints specified in Part 2 of this guide.
- If you have ground triangles one above the other, be sure they are separated into different Ground objects, as the game can only detect one triangle per Ground object, so they cannot be in the same Ground.
- Only convex polygons are supported. If you have concave polygons as grounds, convert them to triangles.
- A non-wall ground serves as both a ground you can stand on, as well as a ceiling when touching it from below. This is why you can walk on ceilings when using glitches in the game, and why their face is oriented to the up and not the down.
- When importing, the editor will replace grounds that have the same names as the objects exported in the OBJ file. This way, you can for example make a single change to an object in the OBJ, and as long as the name remains the same, it will replace the Ground while keeping the behavior flags the same as before.
- Prefer few big triangles over too many small triangles if possible.
- Once you're satisfied with the Grounds, the last thing would be to make a rendered model of your sector. You can do it with your favorite 3D modelling software and a plugin to export the model as Renderware DFF format (for Blender you have the DragonFF plugin). Then you import it by selection the new sector's root scene node in the Scene graph window and click the Import DFF button.
- You might notice that the AI-controlled heroes (Obelix, Dogmatix) might not follow the leader (Asterix). This is because there are no pathfinding grids at the new sector. You can quickly add a new pathfinding grid in the Pathfinding window and position it such that it covers the new sector.