Sites


Creating Point and Click Games with Escoria

Terrain: Light and Perspective

The last feature of Escoria you will certainly like to use is to define a walkable area for you main player character: a terrain. This terrain can also affect the character scale to simulate perspective, and the character brightness and color to simulate light in your main scene.

Technically, the "terrain" node contains all the information about the walkable areas of your scene. In this area, the player will be able to make the main character walk. If the character goes far away in the landscape, he will be smaller according to the perspective using the Scalesproperty, if he goes into a zone without much light, it will be darker, and vice versa using theLightmapproperty. The terrain will define theses areas precisely.

A terrain node should be added in your main scene, probably just after the background node, like in this example:

 Escoria second scene structure example

A walkable area first

The "terrain" node consists of a node of type Navigation2D, with the script globals/terrain.gd attached to it. To define a walkable area, add one or more children nodes with pathfinder area information, a node of type NavigationPolygonInstance.

Escoria Terrain Creation A

Then in the Navpoly property of the inspector, create a New NavigationPolygon. Use the pencil in the toolbar of the central panel to create a polygon. Click on the first point again to close it, it should be filled with green. You can edit it with the second tool next to the pencil.

 Escoria Terrain Creation B

So we have a simple walkable area now. You can add holes in your terrain by clicking again on the pencil tool and drawing inside your first polygon.

Maybe your walkable area is divided in several part, or maybe an action will change the walkable area (unlock some part for example): in those cases, create other NavigationPolygonInstance nodes. By scripting with the set_state function, you should be able to place an item in your scene with animations that control the "Enabled" property of each NavigationPoligonInstance node.

Here is an example of a finished polygon:

Escoria terrain example poly

Light and perspective using pictures maps

Whether you have one or many polygons, the character scale or light will not be modified by its position on the terrain yet. To achieve that, first, you will need to create two PNG images per polygon: one for light, one for scale. The pictures should have the same shape as the area, but can be smaller in pixel and cropped to the be used only in the needed zone to save some memory (we will upscale it later with the Bitmaps scale property)

For light, you will create a grayscale picture, a lightmap, where full light is defined by full white and the full shadow is defined by full black. You can use all the values of gray for nuances. You can also create an RGB pictures with full colors, so your shadows and light will be colored, but keep in mind the lightness values of your colors, unless you are doing a dancefloor scene!
For perspective, you will create a blue picture, a scale map, using only blue values on the blue channel: full blue is the closest, no blue is the farthest. The simplest way to do that in your image editor is to lock or disable other channels than blue and paint a black and white gradient as a starting point: black will be the farthest, white will be the nearest.

With your pictures done, click again on the terrain node in Godot, the terrain script show several parameters:

  • "scales" is the image with the scale map to be used in the scene.
  • "lightmap" is the image with a light map to be used in the scene.
  • "bitmaps_scale" a scale value applied to the "scales" and "lightmap" images. Since these images are bitmaps, we don't want them to be as big as the background, a lightmap and scale map can be considerably smaller (4x or 8x smaller for example), and scaled to match the size of the terrain using this parameter
  • "debug_mode" used for displaying the scales or lightmap images on top of the terrain during editing
  • "modulate" a global lighting value, used to modulate all objects in the scene that are affected by lighting. Recommended if you didn't draw your items following the main scene's lighting
  • "scale_min" and "scale_max". A range of minimum and maximum scales, the value from the "scales" image will be adapted to this range.

Keep in mind that the "scales" and "lightmap" bitmaps are contained within the node, and they don't reference an external file. If you change your bitmap files, you need to load the again in the node.

 Here an example of a scales map:

Escoria terrain example Scale map

 Here an example of a lightmap:

Escoria terrain example Scale map

 ⚠ For now a small bug in Godot prevents us from saving our maps into in a .tscn (text based) scene format, so you should use the .scn (binary) format as a workaround until that's fixed.

Middle ground objects for more perspective

You can also add objects in your scene so the player can be in front or behind them depending on his position on the terrain, to give additional depth to your scene.

They must be separate sprites, usually placed with Sprite nodes, and they must have two properties to be correctly handled by Godot and Escoria:

  • An offset so the origin of the sprite (the cross which is by default in the center) is at the bottom of the sprite: a negative value in the Y "offset" property. Passing this point, the player will be behind the middle ground object. Depending of the object, it can be a good idea to have a hole in your terrain polygon around the object so the player can't go through.
  • The globals/item.gd script must be attached to the Sprite node so it's detected by the game engine. No item parameters are necessary (not even a global_id)

Escoria terrain example middle ground object

 

Foreground objects

To ensure your foreground sprites are always on top, you should place them after the player in the node tree, and give them an high value in their Z property.

Escorai terrain example foreground object

If you have items on top of your foreground objects, give them an even higher Z value, and don't forget to also check on the "Use custom Z" property.

Escorai terrain example foreground item

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.