Force feedback for Windows

edit:
TEN YEARS LATER

skaughtx0r redid this, source is on git. Thanks to everyone helping fix this.

Hi, we’re working on a vehicle simulator, so one of the things we need is force feedback (eg steering wheels). The Unity input system doesn’t have it, so here it is :slight_smile:
It’s a PRO only feature as it’s a C++ plugin which uses DirectInput.
This is a first successful test but it needs some work. The show stopper at the moment is a crash bug. It’s a weird one, where the FIRST time you run it in the Unity editor, it runs fine. You click stop, then if you click play again, Unity will crash. Odd. I presume it’s some cleanup issue but I can’t find it. Any help would be great.
It’s a modification of the DirectX June 2010 SDK DirectInput FF sample.

ps Unity, can we please get script access to the input system?

edit: If you can help go here where we’re discussing what the problem might be
http://forum.unity3d.com/threads/78580-Force-feedback-plugin?highlight=force+feedback

501186–17730–$UnityForceFeedback.zip (87.2 KB)

1 Like

I have seen your comments on native stereo here: http://feedback.unity3d.com/forums/15792-unity/suggestions/762128-native-stereoscopic-3d-rendering
if you are not Cameron Bonde, then sorry.

I just have one question have you ever implemented stereoscopic 3d in unity?

Hey, yeah I have. PM me about it. I’ve done chromadepth and ‘normal’ passive 3d. Not anaglyph or interlaced or any tricky techniques.

BTW, about the force feedback crash, I’ve got a post over on support since I still need help on it.

Good

Fantastic plugin, Cameron. :slight_smile:

Awesome.

Sent you a PM.

I fixed your issue with the plugin. You did not reset the number of axis to zero before enumerating them, so at the second launch, you tried to create the effect with double the axis which are available, leading to E_INVALIDARG. The subsequent call on the uninitialized effect pointer leads to the access violation that crashes Unity.

653895–23335–$FFConst.zip (3.22 KB)

Edit: Btw, you can make a debug build of the plugin, copy that to the Assets folder and then attach the Visual Studio debugger to Unity. You can then set breakpoints in the plugin.

Beautiful! I wasn’t looking forward to tracking that down. I’ll test it and if it works I’ll stick it up on the Asset store for free, not worth charging for I think. Give me a PM with your real name and I’ll put a note in the header if you’d like

It really wasn’t a big deal, at least with the debugger. Stepping through the code, I noticed the wrong number of axis at the second initialization. I also changed the cooperative mode to background, which should still work for most joysticks and wheels, and the acquisition stays when the window focus is lost. Note in the header is not necessary, but thanks.

Force feedback would make a great addition to the Asset Store. I’m sure many devs will appreciate it. :slight_smile:

Hi !
Force feedback work well ! … the first time !
Vectrex, can you please update the zip with Graealex fix ? I don’t know anything about visual studio.

Got a 2nd question :

  • the wheel rotation is 180°, how to have the full 900° of G25/27 ?

tks

I have the exact same questions.

I patched and recompiled the plugin:

776717–28425–$UnityForceFeedback.zip (626 KB)

To get the full 900° rotation with G25/G27 use the Logitech Gaming Software Profiler and use the properties of the steering wheel to set to full range.

Awesome graealex! Thank you.

If you have problems with the DLL, either download and install “Microsoft Visual C++ 2010 Redistributable Package”, or download this static build that doesn’t require the MSVCRT libraries.

777429–28438–$UnityForceFeedback_static.zip (1.21 MB)

1 Like

move to Unity3.5 today, Test Demo Crash Editor and show this message on my pc:

Unity Editor [version: Unity 3.5.0f5_dae8896b94af]

UnityForceFeedback.dll caused an Access Violation (0xc0000005)
in module UnityForceFeedback.dll at 0023:6a3412d3.

graealex, would you like to make this plugin works on Unity 3.5 again ? :wink:

Hey guys,

I’ve just tested on:
-Windows 7 Ultimate
-DX11
-Unity 3.4.0f5
-MS Visual C++ 2010
-Logitech G27

Crashes with the same Access violation as FXCarl received. @FXcarl ever find a solution?

@graealex any ideas what the problem causing this is?

Hi,
I put the library in my project using unitycar but the force feedback only works on the unity of the game window. When I create the build the force feedback does not work.
I’m using the InputManager unitycar.
Anyone know if I need to do some special configuration?

It’s working fine on both of my steering wheels in the latest version of Unity. The only times it has ever crashed for me is when I run it without the force feedback device plugged in.

However, I wish more parameters from the device could be exposed.

ive been messing with this and wondered if anybody is still getting the bug that makes it crash every time the editor is restarted… thanks.

3.5.3 Pro
Windows 7
Ultimate 64
DX9
DX11

Ive tried all three on this page.

Thanks
Kevin