Game logic - Controller – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "[[Ylands " to "[[Ylands:")
(7 intermediate revisions by 2 users not shown)
Line 7: Line 7:
**Controller is active even if the object is not possessed.
**Controller is active even if the object is not possessed.


=Setup=
= 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.
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.
*Currently only capsule collision envelope is avalable


==Object setup==
#Select an object you wish to control
*Select an object you wish to control
#Set the object as "Animated"
*Set the object as "Animated"
#Enable "Can be possessed" atribute
*Enable "Can be possessed" atribute
#Optionally: Set collision envelope
*Optionally: Set collision envelope


===Collision setup===
<gallery>
Image:Ylands-Editor-Controller 1.png|Object setup
</gallery>
 
=== Collision setup ===
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.
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====
*Envelope parameters
*'''Snaps to platforms''' - Whenever the object can snap to other platforms
**'''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.
**'''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.  
**'''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.
**'''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
*Envelope size and position can be tweaked using the "Edit" button
Line 31: Line 33:
**'''Height''' - Capsule Collider  height.
**'''Height''' - Capsule Collider  height.


==Controller setup==
===== Note =====
*Custom controls
*Object forward direction is aligned with its Z axis. It is possible to use "Edit pivot" on welds to change its orientation.
*Enable Custom controls automatically
 
<gallery>
Image:Ylands-Editor-Controller 2.png|Object setup
Image:Ylands-Editor-Controller 3.png|Object axes
Image:Ylands-Editor-Controller 4.png|Collision envelope
</gallery>
 
=== Controller setup ===
Setup of Controller itself is actually simple. However it is possible to assign [[Ylands:Game logic - Custom controls|'''Custom controls''']] to a controller, enabling custom actions of those Custom Controls to be used by the Controller via [[Ylands:Tile - Controller - get key action|'''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.
 
*[[Ylands:Tile - Controller - get-set controller|'''Get / Set controller''']] - allows to assign controller to a object.
*[[Ylands:Tile - Controller - get-set possesed object|'''Get / Set possessed object''']] - allows to posses a object.
 
==== Note ====
*It is possible to use [[Ylands:Tile - Null literal|'''None''']] to remove a controller or stop possession.
 
= Controller script =
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.
 
=== Controller variables ===
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 [[Ylands:Tile - Controller - get-set parameter|'''Set parameter''']] instruction.
**Useful for differentiating controller parameters for different possessed objects (i.e. car acceleration).
 
<gallery>
Image:Ylands-Editor-Controller 5.png|variable
</gallery>
 
=== Controller instructions ===
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.


==== Player input ====
*[[Ylands:Tile - Controller - get primary input|'''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


==Visual scripting==
*[[Ylands:Tile - Controller - get secondary input|'''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


===Controller assign===
*[[Ylands:Tile - Controller - get key action|'''Get key action''']] - Returns whenever selected Custom key action is triggered.
**Appropriate [[Ylands:Game logic - Custom controls|'''Custom controls''']] must be linked to the Controller.


===Object posses===
===== Note =====
*Gamepad is currently partially supported in Ylands.


===Controller script===
==== Other instructions ====
*[[Ylands:Tile - Controller - is grounded|'''Get/Set orientation''']] - Returns whenever the object is touching ground or other object.
*[[Ylands:Tile - Controller - get position|'''Get/Set orientation''']]
*[[Ylands:Tile - Controller - get-set velocity|'''Get/set velocity''']]
*[[Ylands:Tile - Controller - get-set orientation|'''Get/Set orientation''']]





Revision as of 17:36, 16 November 2022

Description

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.

  1. Select an object you wish to control
  2. Set the object as "Animated"
  3. Enable "Can be possessed" atribute
  4. Optionally: Set collision envelope

Collision setup

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.
Note
  • Object forward direction is aligned with its Z axis. It is possible to use "Edit pivot" on welds to change its orientation.

Controller setup

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.

Note

  • It is possible to use None to remove a controller or stop possession.

Controller script

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.

Controller variables

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).

Controller instructions

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.

Player input

  • 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
Note
  • Gamepad is currently partially supported in Ylands.

Other instructions