-
Notifications
You must be signed in to change notification settings - Fork 11
Platform Actor
The Platform Actor is one of the main features of the template. It consists of a set of useful behaviors an actor has in the context of a platformer game.
An actor is an entity that acts with purpose in the game's world. Actors can be a Player, an Enemy with AI and any sort of smart entity with some sort of intelligence.
The main goal with the Platform Actor is to have a self contained entity with useful built-in behaviors that can be used for setting up basic platform gameplay mechanics. To achieve that the Platform Actor leverage its behaviors from well established references in the genre.
To establish a broad, yet specific and well defined and scoped, library of behaviors the platform actor takes advantage of what, in my experience, are good references for what Pigdev Studio is aiming to achieve in its games. The references below appear in order of importance and influence in the Platform Actor's design.
Megaman X series offers a snappy yet fluid physics. The actor always move at a constant speed, no acceleration. A Heavy gravity guarantees that each jump will have a fast landing time, offering a good feeling of precision of the jump by decreasing the tension of anticipation lower gravity jumps, e.g. Mario Bros., offer. This kind of physics are ideal for fast paced action games because they avoid lagging feedback, e.g. waiting the acceleration time to reach the full walk speed.
The wall slide and wall jump is almost a trademark of Megaman X games, and is a must have for the Platform Actor as well. This feature offers a smooth landing, and it is good for games that have a bit of exploration in their levels by offering a safer way to climb down levels' pits and explore potential secret areas. It is also a good feature for combat mechanics, especially if combined with moving platforms or boss's pits.
Currently the Platform Actor can perform a lot of the basic movement features already:
- Walk
- Dash (and air dash)
- Jump (multiple times before landing)
- Wall Slide
- Wall Jump
- Climb (ladders)
- Jump through specific platforms
All the above features have their own configurable properties plus the actor's own configurable properties, to allow the flexibility needed to create a good range of games with unique mechanics.
Every time the actor performs an action it emits a signal
with the name of the action performed, this allows for an easy way to setup animations. The actor's state_machine
also emits a signal every time it changes its states, making available to know both the previous and the current state, which makes animation transitions easier.
For the implementation of the Platform Actor a simple Finite State Machine was used, along with a Layered Class Architecture. This offers a simple way to use and modify its behaviors.
The actor by itself only reacts to collisions and move at a given velocity
, everything else, including the velocity calculations, is delegated to a given state
.
The direction the actor is moving towards.
The actor's movement velocity, used in KinematicBody2D.move_and_slide()
as the linear_velocity
parameter.
The state_machine responsible for handling the state
the actor shall be at the moment.
The acceleration force pulling the actor towards the floor.
The normal a collision will use to consider if the actor is_on_floor
. See KinematicBody2D.move_and_slide for more.
The speed in which the actor can be considered as idling on a slope, i.e. not moving. See KinematicBody2D.move_and_slide for more.
The angle in degrees that the actor can start consider a slope as a wall, i.e. is_on_wall
becomes true
. See KinematicBody2D.move_and_slide for more.
The velocity in the vertical axis that the character will enter in a fall
state
.
A configuration parameter that tells whether the character will be able to perform a dash
or not.
Emitted by an state
whenever the actor enters it or when specific events are triggered inside the state
without changing the current state
.
Called whenever actor.direction
changes, used mostly to update sprites looking direction.
Sets the state_machine.state
to idle
.
Sets the state_machine.state
to walk
.
Sets the state_machine.state
to dash
if can_dash
is true
.
Sets the state_machine.state
to wall
.
Sets the state_machine.state
to climb
.
Sets the state_machine.state
to jump
.
Sets velocity.y
to 0.
Sets the state_machine.state
to fall
.
Simply emits a action_performed
with a stop
argument, can be used to tell an AnimationPlayer
to stop an animation.