Triggering the vibration functionality of a controller¶
This example shows, how to call activate the vibration of a controller for a certain amount of time. Some controllers have different axes, which can vibrate, but some controllers support only a single axis. If this is the case the axis parameter will be ignored and can should be set to 0.
vr/controllerVibration.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3class ControllerFeedback:
4 def __init__(self):
5 self.vibrationDuration = 250
6 self.vibrationAxis = 0
7 # Attach controller to a signal to trigger the actual vibration
8 pointer = vrDeviceService.getInteraction("Pointer")
9 executeAction = pointer.getControllerAction("execute")
10 executeAction.signal().triggered.connect(self.vibrate)
11
12 def vibrate(self, action, device):
13 # Let a controller axis vibrate for a certain amount of time.
14 # Note: Most controllers only support one axis with id 0.
15 device.vibrate(self.vibrationDuration, self.vibrationAxis)
16
17feedback = ControllerFeedback()