Game logic - Controller – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "{{DEFAULTSORT:{{#sub:{{PAGENAME}}|19}}}}" to "{{DEFAULTSORT:{{#sub:{{PAGENAME}}|13}}}}")
 
(4 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.


=Object and Controller 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.


Line 19: Line 19:
</gallery>
</gallery>


===Collision setup===
=== 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.


Line 32: Line 32:
**'''Radius''' - Width of the collider.
**'''Radius''' - Width of the collider.
**'''Height''' - Capsule Collider  height.
**'''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.


<gallery>
<gallery>
Line 39: Line 42:
</gallery>
</gallery>


===Controller setup===
=== 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.
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  
*'''Custom Controls''' - Target Custom Controls  
*'''Toggle Controls automatically''' - Whenever Custom controls will be automatically enabled when object is possessed.
*'''Toggle Controls automatically''' - Whenever Custom controls will be automatically enabled when object is possessed.


=Controller and possession assign=
= 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.
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 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.  
*[[Ylands:Tile - Controller - get-set possesed object|'''Get / Set possessed object''']] - allows to posses a object.  


====Note====
==== Note ====
*It is possible to use [[Ylands Tile - Null literal|'''None''']] to remove a controller or stop possession.
*It is possible to use [[Ylands:Tile - Null literal|'''None''']] to remove a controller or stop possession.


=Controller script=
= 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 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===
=== Controller variables ===
Member variables of the local script are of two types - states and parameters.  
Member variables of the local script are of two types - states and parameters.  


Line 67: Line 70:
*'''Parameter variable'''
*'''Parameter variable'''
**Must be enabled in properties when creating new 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.
**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).
**Useful for differentiating controller parameters for different possessed objects (i.e. car acceleration).


Line 74: Line 77:
</gallery>
</gallery>


===Controller instructions===
=== 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.
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====
==== Player input ====
*[[Ylands Tile - Controller - get primary input|'''Get primary input''']] - Unnormalized primary horizontal and vertical input.  
*[[Ylands:Tile - Controller - get primary input|'''Get primary input''']] - Unnormalized primary horizontal and vertical input.  
**'''Keyboard''' - keys WSAD, value 0 or 1  
**'''Keyboard''' - keys WSAD, value 0 or 1  
**'''Gamepad''' - right stick, values 0 to 1
**'''Gamepad''' - right stick, values 0 to 1
**'''Mobile''' - virtual joystick, values 0 to 1
**'''Mobile''' - virtual joystick, values 0 to 1


*[[Ylands Tile - Controller - get secondary input|'''Get secondary input''']] - Unnormalized secondary horizontal and vertical input.  
*[[Ylands:Tile - Controller - get secondary input|'''Get secondary input''']] - Unnormalized secondary horizontal and vertical input.  
**'''Mouse''' - X/Y movement, values 0 to (theoretical) infinity
**'''Mouse''' - X/Y movement, values 0 to (theoretical) infinity
**'''Gamepad''' - left stick, values 0 to 1
**'''Gamepad''' - left stick, values 0 to 1
**'''Mobile''' - X/Y screen finger movement, values 0 to (theoretical) infinity
**'''Mobile''' - X/Y screen finger movement, values 0 to (theoretical) infinity


*[[Ylands Tile - Controller - get key action|'''Get key action''']] - Returns whenever selected Custom key action is triggered.
*[[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.
**Appropriate [[Ylands:Game logic - Custom controls|'''Custom controls''']] must be linked to the Controller.


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


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




----
----
{{Navbox/Ylands}}
{{Navbox/Ylands}}
{{DEFAULTSORT:{{#sub:{{PAGENAME}}|19}}}}
{{DEFAULTSORT:{{#sub:{{PAGENAME}}|13}}}}


[[Category: Game Logic]]
[[Category: Game Logic]]
[[Category: Ylands 1.6]]
[[Category: Ylands 1.6]]

Latest revision as of 14:21, 24 November 2023

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