Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Seth-Bergman · Feb 17, 2012 at 02:22 AM · vibration

XInput: how do I access vibration on 360 controller?

I'm working on a fighting game, using two 360 controllers for 2 players. To get this to work, I've added xInputPureDotNet to my project. Works perfectly, only minor bug seems to be it detects controller 1 as 2 and vice versa, not a big problem to work around. So, In the sample unity project xInputTest which is included, there is a line accessing vibrate for each motor based on trigger input. Since I don't really fully understand how xinput works, I've been trying to use that example to add force feedback to my own project. The line for vibration is :

 Gamepad.SetVibration(playerIndex, state.Triggers.left,state.Triggers.right);

By exposing the state.Triggers.left,state.Triggers.right in the inspector, they appear as normal axis input, maxing out at 1.

However, if I plug in a 1 through code, such as :

var vib1 = 1; var vib2 = 1; Gamepad.SetVibration(playerIndex, vib1,vib2)

(the format is SetVibration(XInputDotNetPure.PlayerIndex,float,float))

Doesn't seem to matter what number I use, all I get is a faint murmur on one controller. The xinput test only seems to take input from one controller (controller 2), so what I want to figure out is:

A: how can I set up the xinputdotnetpure.PlayerIndex for each controller, since the example only seems to work for one? Note: the test detects both controllers, as evidenced in the debug log. Only seems to take input from one though. All I need is to be able to refer to each controller as a PlayerIndex.

B: since the two latter arguments are floats, can't I just set them manually? Why doesn't this work? In the test scene, (using the state.Trigger.right etc.) the vibrate fully works, at least on the one controller. But if I replace with my own floats, just a faint murmur.

If there's anyone out there who knows how to do this, an example would be extremely helpful.. Thanks in advance for any ideas!

Update:figured out the PlayerIndex, it's PlayerIndex.One, PlayerIndex.Two, etc. so now I've got the vibrate basically working, just not as strong as I'd like it to be. Here's the script I'm using, in case anyone's interested:

 using UnityEngine;
 using XInputDotNetPure; 
 
 public class XInputVibrateTest : MonoBehaviour
 {
     public float testA;
     public float testB;
     public float testC;
     public float testD;
 
     void Update()
     {        
         GamePad.SetVibration(PlayerIndex.Two,testA,testB);
         GamePad.SetVibration(PlayerIndex.One,testC, testD);    
     }    
 }

then I just set the floats when I want vibration (again, doesn't seem to matter much WHAT I set them to, that's the issue now.. I think it goes 0 to 1, but I can't get the full vibration as in the demo project no matter what I try.)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Seth-Bergman · Jan 06, 2013 at 03:34 AM

In response to this more recent post, I have just revisited this issue. It seems the problem was the part "PlayerIndex.One" "PlayerIndex.Two"... instead I believe simply replacing "0" and "1" would do it, as in:

  GamePad.SetVibration(0,testA,testB);
  GamePad.SetVibration(1,testC, testD);  

(for controller 3 it would be "2", and for controller 4 it would be "3")

(well, I don't know if that was the issue, doesn't really make sense, but at any rate, all seems to work fine now..)

for a javascript example, see my answer in the link :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by JtheSpaceC · Dec 14, 2015 at 02:47 PM

The accepted answer didn't help me. I've failed to get this done about a dozen times until today. You need to download a 'using' namespace to get access to the GamePad function.

The download and instructions (scroll down) can be found here. Enjoy! https://github.com/speps/XInputDotNet

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PhoenixRising1 · Jan 13, 2016 at 05:44 PM 1
Share

Thanks a bunch!

avatar image
0

Answer by OZAV · Feb 20, 2014 at 02:48 PM

I also have enabled the RUMBLE function, for my FPS game dev, by using the XInputDotNetPure system and it works ok for game pad vibration, but - at the times - i get the permanent vibration that does not stop, after some heavy objects hit the Player, or his camera ... the player has a rigidbody, so, could that be related to the problem, anyone ? Let's shed some light on this, i would not like to think it's a unity bug - i don't think so, in this case.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

XInput: vibration on more than 4 360 controller? 0 Answers

Vibration when moving into colliders 1 Answer

Making a Vibraating string. Need Help!! 0 Answers

Xbox one controller vibration 0 Answers

XInput in published builds 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges