This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.ControlsGamepad Class

Inherits from: Controls

This class handles game pads input (XBox 360, Xbox One, Sixaxis, etc.). It provides access to the following controller properties:

  • Buttons represent digital buttons on the controller and can be either pressed or unpressed. Just like in the case of mouse/keyboard controls, they can be mapped to the specific controls states, to bind input events and programmed actions. You can either bind buttons in the code via SetStateButton() or let the user assign the button for a control state via GetStateEvent().
  • D-pad is represented as four directional buttons (left, right, up and down). They are handled in the same way as other buttons.
  • Thumbsticks are left and right analog directional sticks on the controller. They are queried via LeftX and LeftY for the left thumbstick and RightX and RightY for the right one. Thumbsticks also act as two digital buttons when pressed (i.e. the stick is "clicked" in). In this case, they are handled in the same way as other buttons.
  • Triggers are two analog controls that can be queried for their states via LeftTrigger and RightTrigger.
  • Vibration motors allow to set vibration effects. The left motor is a low-frequency rumble motor, while the right motor is a high-frequency one. The amount of vibration for each of the motors can be set via the setVibration() method.

Input data from analog controls (thumbsticks and triggers) can be additionally filtered via Filter to provide smooth interpolation between frames and avoid jerks.
A controller should update the physical state of all its input controls (i.e. check whether the user has pressed the button, for example) each frame using UpdateEvents().

ControlsGamepad Class

Properties

int Number#

The game pad number (up to four game pads are supported).

int PlayerIndex#

The index of player for the game pad. Some devices support connection of multiple players (e.g., XBox 360 supports up to four players connected through XBox 360 game pads).

bool IsAvailable#

The value indicating if the game pad is available.

string Name#

The user-friendly name of the game pad. If you want to get the type of the game pad, use DeviceType

int DeviceType#

The device type. One of the Input.DEVICE_TYPE_* values indicating whether it is a wheel, throttle, or other device.

int ModelType#

The game pad model type identifier.

float Filter#

The filter value used to correct the current state of the game pad axis relative to the previous one:
  • Filter value of 0 means there is no interpolation and the current value is not corrected.
  • Filter value of 1 means the previous state is used instead of the current one.

float RightTrigger#

The axis state value (the position) of the right trigger. zero means the trigger is not pressed; 1 means the trigger is pressed to the maximum.

float LeftTrigger#

The axis state value (the position) of the left trigger. zero means the trigger is not pressed; 1 means the trigger is pressed to the maximum.

float RightY#

The state value of the right thumbstick along the Y-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate down; positive values indicate up.

float RightX#

The state value of the right thumbstick along the X-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate left; positive values indicate right.

float LeftY#

The state value of the left thumbstick along the Y-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate down; positive values indicate up.

float LeftX#

The state value of the left thumbstick along the X-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate left; positive values indicate right.

bool IsStateEvent#

The value indicating if a game pad button is successfully assigned to a state.

Members


ControlsGamepad ( int num ) #

Constructor. Createas a ControlsGamepad with the specified number.

Arguments

  • int num - Game pad number.

int UpdateEvents ( ) #

Scans the game pad controls (synchronizes game pad button states with the controller itself). Should be called each frame.
Notice
On Windows, in case a game pad is not connected, this function can substantially increase per-frame update time. (This happens due to calling IDirectInput8::EnumDevices() method.)

Return value

0 if a game pad is not found or updateEvents() already has been called for the frame; otherwise 1.

void SetVibration ( float low_frequency, float high_frequency, float duration_ms = 100.0f ) #

Sets the amount of vibration for the right (high-frequency) and left (low-frequency) motors for the time period specified in milliseconds.

Arguments

  • float low_frequency - Vibration value in the [0.0f; 1.0f] range for the left (low-frequency) motor.
  • float high_frequency - Vibration value in the [0.0f; 1.0f] range for the right (high-frequency) motor.
  • float duration_ms - Vibration period duration, in milliseconds.

int GetButton ( int button ) #

Returns a button state (pressed or not pressed).

Arguments

  • int button - Button number.

Return value

1 if the button is pressed; otherwise, 0.

int ClearButton ( int button ) #

Returns a button state and clears it to 0 (not pressed).

Arguments

  • int button - Button number.

Return value

1 if the button is pressed, and this function was not called previously in the current frame; otherwise, 0.

void SetStateButton ( int state, int button ) #

Sets a game pad button that switches a given state on or off.

Arguments

  • int state - State (one of the CONTROLS_STATE_* variables).
  • int button - Button number.

int GetStateButton ( int state ) #

Returns a game pad button that switches a given state on and off.

Arguments

Return value

Button that switches the given state.

string GetStateName ( int state ) #

Returns the name of a given state, that was assigned to one of controls.

Arguments

Return value

State name.

bool SaveState ( Stream stream ) #

Saves ControlsGamepad settings into the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
ControlsGamepad gamepad = new ControlsGamepad(1);
gamepad.SetStateButton(0,1);

// save state
Blob blob_state = new Blob();
gamepad.SaveState(blob_state);

// change the node state
gamepad.SetStateButton(2,1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
gamepad.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the ControlsGamepad settings are saved successfully; otherwise, false.

bool RestoreState ( Stream stream ) #

Restores ControlsGamepad settings from the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
ControlsGamepad gamepad = new ControlsGamepad(1);
gamepad.SetStateButton(0,1);

// save state
Blob blob_state = new Blob();
gamepad.SaveState(blob_state);

// change the node state
gamepad.SetStateButton(2,1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
gamepad.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the ControlsGamepad settings are restored successfully; otherwise, false.

void GetStateEvent ( int state ) #

Lets the user assign a game pad button to a given state.

Arguments

  • int state - State (one of the CONTROLS_STATE_* variables), to which a button is going to be assigned.

int IsStateEvent ( ) #

Returns a value indicating if a game pad button is successfully assigned to a state.

Return value

1 if a button is already assigned; otherwise, 0.
Last update: 2022-12-14
Build: ()