Skip to content

Platform Actor

Henrique Campos edited this page Sep 11, 2018 · 7 revisions

Description

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.

Objectives

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.

References

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 (Main Reference for Physics and Movement)

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.

Megaman X basic movement and physics demo

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.

Megaman X Wall Jump Megaman X Wall slide

Features

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.

Programming Interface

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.

KinematicBody2D platform_actor.gd

Members

int direction

The direction the actor is moving towards.

Vector2 velocity

The actor's movement velocity, used in KinematicBody2D.move_and_slide() as the linear_velocity parameter.

StateMachine state_machine

The state_machine responsible for handling the state the actor shall be at the moment.

Constants

float GRAVITY

The acceleration force pulling the actor towards the floor.

Vector2 FLOOR_NORMAL

The normal a collision will use to consider if the actor is_on_floor. See KinematicBody2D.move_and_slide for more.

float SLOPE_STOP_SPEED

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.

float SLOPE_MAX_DEGREE

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.

float FALL_THRESHOLD

The velocity in the vertical axis that the character will enter in a fall state.

Configuration

bool can_dash

A configuration parameter that tells whether the character will be able to perform a dash or not.

Signals

action_performed(string action)

Emitted by an state whenever the actor enters it or when specific events are triggered inside the state without changing the current state.

direction_changed(int new_direction)

Called whenever actor.direction changes, used mostly to update sprites looking direction.

Methods

idle()

Sets the state_machine.state to idle.

walk()

Sets the state_machine.state to walk.

dash()

Sets the state_machine.state to dash if can_dash is true.

wall_slide()

Sets the state_machine.state to wall.

climb()

Sets the state_machine.state to climb.

jump()

Sets the state_machine.state to jump.

cancel_jump()

Sets velocity.y to 0.

fall()

Sets the state_machine.state to fall.

stop():

Simply emits a action_performed with a stop argument, can be used to tell an AnimationPlayer to stop an animation.