Ylands:Game logic - Controller
Controller allows to animate objects using Visual scripting and is responsible for capturing players input. Any object with controller assigned can be then possessed and controlled by a player. In order to achieve smooth movement, controlled objects are simulated locally on the client and automatically synchronized with the server. Due to the multiplayer constraints, the controller script is severally limited in comparison to "standard" visual scripting, we call this local scripting.
- Controller allows players to posses an object.
- An object can be controlled (possessed) only by one player.
- One controller can be assigned to multiple objects.
- Controller is active even if the object is not possessed.
Object and Controller setup
In order to make an object eligible for possession, first it has to be animated and allow "possession". Optionally it is possible to also setup a collision envelope, so that the object will collide with world.
- Select an object you wish to control
- Set the object as "Animated"
- Enable "Can be possessed" atribute
- Optionally: Set collision envelope
Enabling collision envelope will enable the object to collide with terrain and other entities. Currently the controller is using modified character controller, so the envelope shape is limited to capsule.
- Envelope parameters
- Snaps to platforms - Whenever the object can snap to other platforms
- Slope limit - Limits the collider to only climb slopes that are less steep (in degrees) than the indicated value.
- Step offset - The collider will step up a stair only if it is closer to the ground than the indicated value.
- Skin width - Two colliders can penetrate each other as deep as their Skin Width.
- Envelope size and position can be tweaked using the "Edit" button
- Center - Collider offset in world space.
- Radius - Width of the collider.
- Height - Capsule Collider height.
- Object forward direction is aligned with its Z axis. It is possible to use "Edit pivot" on welds to change its orientation.
Setup of Controller itself is actually simple. However it is possible to assign Custom controls to a controller, enabling custom actions of those Custom Controls to be used by the Controller via Get key action instruction.
- Custom Controls - Target Custom Controls
- Toggle Controls automatically - Whenever Custom controls will be automatically enabled when object is possessed.
Controller and possession assign
Any object eligible for possession, must have a controller assigned first. Objects with controller can be then possessed/unpossessed by any player at will.
- Get / Set controller - allows to assign controller to a object.
- Get / Set possessed object - allows to posses a object.
- It is possible to use None to remove a controller or stop possession.
Controller scripting is using so called "local scripting", which is severally limited in comparison to "standard" scripting. These limitations are imposed by client-server prediction which ensures that controlled objects move smoothly on all clients.
Member variables of the local script are of two types - states and parameters.
- State variable
- Default variable type local to the script.
- Cannot be modified or read from outside of the local script.
- Useful for internal controller calculations (i.e. final velocity).
- Parameter variable
- Must be enabled in properties when creating new variable.
- Can be modified only from outside of the local script via Set parameter instruction.
- Useful for differentiating controller parameters for different possessed objects (i.e. car acceleration).
The aim of controller script is to modify controlled object orientation and velocity based on player input. However it is up to the scripter to ensure how the input will be translated into the resulting object movement.
- Get primary input - Unnormalized primary horizontal and vertical input.
- Keyboard - keys WSAD, value 0 or 1
- Gamepad - right stick, values 0 to 1
- Mobile - virtual joystick, values 0 to 1
- Get secondary input - Unnormalized secondary horizontal and vertical input.
- Mouse - X/Y movement, values 0 to (theoretical) infinity
- Gamepad - left stick, values 0 to 1
- Mobile - X/Y screen finger movement, values 0 to (theoretical) infinity
- Get key action - Returns whenever selected Custom key action is triggered.
- Appropriate Custom controls must be linked to the Controller.
- Gamepad is currently partially supported in Ylands.
- Get/Set orientation - Returns whenever the object is touching ground or other object.
- Get/Set orientation
- Get/set velocity
- Get/Set orientation