Sites


Creating Point and Click Games with Escoria

Main Player

The main player is the character controlled by the user of the game. The main player is handled as a special type of Item, it uses its own script, and there are different rules that apply to it.

  • When the user selects an action on an item, the player will walk to that item (unless it's configured not to).
  • The player position is saved in savegames.
  • Players also are scaled and lighted by the terrain of the main scene, and they walk inside it using a path finder.
  • Players have animations and states like a normal Item, but they can also have special kinds of animations that depend on the angle they're facing for walking, talking and idle.

When your main scene contains a player that can be controlled by the user, you must instance the player in that scene. There is no main player instanced "globally" that is moved from scene to scene, it's up to you to provide a player in the current scene, if it has one. Keep in mind that not all scenes must have a character controlled by the user.

An example player scene can be found in scenes/test/player.scn

sample of a basic player in godot

The player scene

The player scene is relatively simple, there are few requirements for it to function inside the game. However, player will usually end up being complex scenes, due to their high animation requirements. The basic scene structure is:

  • A root node of type Node2D, named player, with the script globals/player.gd attached to it.
  • An optional node of type AnimationPlayer named animation, which contains all the animations for the character

Anything else necessary (Sprites, sound effects, etc) can be added via normal nodes, and controlled by animations.

The player parameters

The player script contains a few parameters to configure your player. They all appear in the Script Variables part of the Inspector:

speed
the character walking speed in pixels per second. This speed is scaled by the scale of the player, influenced by the scale map of the main scene
v_speed_damp
stands for Vertical Speed Damp. This is used to create the illusion of depth when the characted walks on a terrain with a scale, it affects the speed of the player when it walks vertically (in the Y axis). A value of 0.5 would make the player walk at half speed when walking vertially compared to when walking horizontally. However when walking diagonally, the number only affects the vertical part of the direction.
animations
a gdscript file detailing which animations to use for walking, talking and idle in different angles (see below)
camera_limits
currently ignored
telekinetic
when the player is telekinetic, it will not walk to an object when the user selects an action to perform on it. Keep in mind that this can be controlled from animations

The player animations

There are 3 types of animations that can be configured in the player to play depending on the angle it's facing: walking, speaking and idle. These animations are configured using a gdscript file with 4 simple structures, one defining what are the angles at wich each animation is used, and 3 defining the animation names for each type of animation corresponding to the angles, and a parameter for mirroring the X axis of the animation. This is a very basic example, with only 2 directions, left and right:

# angle "0" is facing the camera, rotates counter clock-wise, angle 90 is profile right, etc
const dir_angles = [ 180, 360 ]
const directions = [ "walk_right", 1, "walk_right", -1 ]
const idles = [ "idle_left", -1, "idle_left", 1 ]
const speaks = [ "speak_left", 1, "speak_right", 1 ]

The dir_angles array lists the angles that serve as limits between one animation as the next. They must be sorted from lower to higher. This list defines 2 ranges of angles, one is between 180 and 360, the other between 360 and 180. As you can see, the first range is defined by the last angle, as the circle wraps around.

The directions array defines the walk animation to use in each range of angles, and a number to be used to scale the X axis of that animation. 1 means leave the animation intact, -1 means mirrored horizontally. Each animation corresponds to a range of the dir_angles list.

The idles array defines idle animations, and the speaks array defines the speaking animations.

Keep in mind that the angles start from 0 when the player is facing the camera, and rotate counter-clockwise. 90 means facing right, 180 means facing the back, etc.

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.