GameInput can manage device output. With force feedback, game input devices can physically move one or more of the device’s input controls to provide tactile feedback to the user. Force feedback works with input devices that simulate vehicle operation, such as driving wheels and flight simulation rigs. These devices contain a force feedback motor that applies force to the controller over an axis. On a racing wheel, it’s a rotational force that turns the wheel to simulate an in-game scenario. Use force feedback with a flight stick to make levers difficult to push or pull from a particular position.
For more information about the GameInput interfaces that support force feedback, see IGameInputDevice and IGameInputForceFeedbackEffect.
Check for a force feedback motor
To create a force feedback effect, you need the IGameInputDevice interface that represents the input device that you want to apply the effect to. After acquiring theIGameInputDevice interface, check the number of force feedback motors on the device by examining the GameInputDeviceInfo struct. This can be done by calling IGameInputDevice::GetDeviceInfo. If there’s a force feedback motor in the input device, the GameInputDeviceInfo member ForceFeedbackMotorCount has a value of one or greater.
Creating a force feedback effect
If a device’s GameInputDeviceInfo struct indicates that it has one or more force feedback motors, create a force feedback effect for the device by calling IGameInputDevice::CreateForceFeedbackEffect as shown in the following code.GameInputForceFeedbackParams struct.
For example, to create a feedback effect with the spring behavior, GameInputForceFeedbackParams consists of the GameInputForceFeedbackEffectKind value GameInputForceFeedbackSpring and the GameInputForceFeedbackConditionParams struct for a spring. Fill in the parameters for your chosen GameInputForceFeedbackEffectKind enum.
After selecting the force feedback motor effect by its index and creating the GameInputForceFeedbackParams struct, call IGameInputDevice::CreateForceFeedbackEffect to create the effect. It’s represented by an IGameInputForceFeedbackEffect interface.
The force feedback effect’s lifetime is associated with the created IGameInputForceFeedbackEffect interface. When the effect is created, it’s loaded to the device. When the last reference is released, the force feedback effect is stopped and unloaded from the device motor.
Applying and updating force feedback effects
When a force feedback effect is created, it’s loaded directly into the device motor. A force feedback motor has a finite amount of memory. This limits the number of force feedback effects that are loaded and played at the same time. Calling IGameInputDevice::CreateForceFeedbackEffect after reaching this limit causes the function to return an error. After creating a force feedback effect, it’s loaded to the force feedback motor in a stopped state. After it’s loaded, use the IGameInputForceFeedbackEffect interface to set the state of the effect toRunning. This plays the effect on the device motor.
States of force feedback effect
A force feedback effect moves through several states to match the current state of the game. It’s important that you update and take note of the state of an effect in accordance with your game to maintain the expected behavior. The states of force feedback can be set according to GameInputFeedbackEffectState as shown in the following code.Stopped state. If a new or stopped feedback effect is set to the Running state, it plays from the beginning of the effect. Setting the state to Paused causes the force feedback effect to stop affecting the motor. However, setting a Paused state effect to Running causes the force feedback effect to apply the effect pattern where it left off.
Stopping an effect ends the effect, but you can trigger the effect again later. For example, when a user leaves rough terrain in a racing game. Likewise, pausing an effect is useful for situations where gameplay is unchanged but the user wants to navigate the UI, such as a pause menu.
Set the state of a force feedback effect by calling IGameInputForceFeedbackEffect::SetState.
Updating a force feedback effect
Adjust the gain of a force feedback effect or provide a new set of parameters if the new GameInputForceFeedbackParams struct shares the same GameInputForceFeedbackEffectKind enum.Gain
Change the intensity of a force feedback effect by adjusting its gain with the IGameInputForceFeedbackEffect::SetGain function as shown in the following code.Setting new parameters
Provide new parameters for a force feedback effect by using the IGameInputForceFeedbackEffect::SetParams function as shown in the following code.GameInputForceFeedbackConstant.
