The Ghost & Object Possession Feature is one of the key features planned to be added for the games beta. Players who die should be able to play as a ghost, allowing them to possess and haunt the game world, effecting its outcome in a controlled fashion through the objects a we allow them to control.
The above functionality was added into the game. The following gif if from a test scene where a ghost possesses a boulder, aims it at various random walker AI's and launches the boulder forward, inflicting damage and killing them. The boulder is the first item to be implemented using the Possessable functionality. Link to the gif
The possession feature was written in vanilla C++11 to be cross-platform for Windows and Mac. It was implemented into our existing game engine following a technique known as the Controller Pilot paradigm, where object functionality is split between the GameObject (object being manipulated), Controller component (Component with accessible methods which has the logic for HOW to manipulate the GameObject) and the Pilot (a class which uses the Controller and determines WHEN and WHAT manipulations to invoke). This style of encapsulating logic allows for very modular code, with Controllers and Pilots being interchangeable very easily without knowing the details of each other.
The GhostCharacter, GhostController and GhostPilot are the three core classes for ghosts. The GhostCharacter is the game object defining the visuals of the Ghost object. The GhostController is the component on the GhostCharacter which allows the GhostCharacter to be controlled. GhostPilots are user pilots which control the GhostController which gathers inputs and has logic in it for alternating between controlling its Ghost body and the objects it possesses.
See: GhostCharacter.cpp, GhostController.cpp & GhostPilot.cpp
BasePossessableController is a component attached to any object which can be possessed by a GhostPilot. When a GhostPilot presses E, it looks for the nearest gameobject with a BasePossessableController in the vicinity and takes it over.
See: BasePossessableController.cpp
Boulder is the first possessable object implemented, with BoulderController component being its controller which subclasses BasePossessableController allowing it to be possessed. When possessed, the BoulderController allows the Ghost to move it around and launch it in the direction its rolling, letting them attack other objects in a hard to control manner.
How To Implement Possessable Objects
See: Boulder.cpp & BoulderController.cpp
When creating future possesable game objects, the object must simply add a component which subclasses BasePossessableController and implements its trigger(Vector2) and move(Vector2) methods, dictating what occurs when the users triggers the object with the space bar (passing in a vector representing the WASD key directions). BoulderController.h is a simple, isolated implementation which can easily be re-purposed for future implementations.