[code] Add feedback (Rumble) to your xBox controller

So, I just found how to enable the force feedback on an xbox controller. I’m surprised that by default it’s not enabled with the UDK.
The solution works in 2 times : your config file and the call of the rumble function.

The config file : DefaultGame.ini

If you don’t have yet a section called [Engine.PlayerController] inside your DefaultGame.ini file you should add it. I found the solution on the official gearbox forum were somebody asked how to disable the rumble. (Thank you google !)

The following code is all you need :

[Engine.PlayerController]
ForceFeedbackManagerClassName=WinDrv.XnaForcefeedbackmanager


Without the forum I could not find this solution. Look at the name of the class !

So why we need this little line inside the ini file ? Well, the answer is inside the player controller class :

// Manages gamepad rumble (within)
var config string ForceFeedbackManagerClassName;
var transient ForceFeedbackManager ForceFeedbackManager;


These two variables manage the controller feedback. Unfortunately, by default the Classname variable is non-existent which make the game unable to manage the feedback. This is why we add the class name inside the config file (because it’s a config variable).

Call the force feedback

In my case and just for testing I quickly made a very little exec function to call a feedback :

//--Gamepad
var ForceFeedbackWaveform GamepadFeedback; //Controller rumble to play


//do a rumble on the gamepad
exec function exe_rumble()
{
	if (ForceFeedbackManager != None)
	{
		`Log("Rumble");
		
		ForceFeedbackManager.bAllowsForceFeedback = true;
		
		//disable all the current rumble
		ClientPlayForceFeedbackWaveform(None,None);
		
		//call our custom rumble
		ClientPlayForceFeedbackWaveform(GamepadFeedback);
		
		SetTimer(0.9,false, nameOf(rumble_stop) );
	}
	else
		`Log("ForceFeedbackManager == None");
}

//stop rumbles function;
function rumble_stop()
{
	ClientStopForceFeedbackWaveform(GamepadFeedback);
	
	//disable all the current rumble
	ClientPlayForceFeedbackWaveform(None,None);
}


//////////////////////////////////////////////////////////////////
// DefaultProperties
//////////////////////////////////////////////////////////////////
DefaultProperties
{
	//////////////////////////////////////////////////////////////////
	// GAMEPAD
	//////////////////////////////////////////////////////////////////
	Begin Object Class=ForceFeedbackWaveform Name=RumbleFeedback
		Samples(0)=(LeftAmplitude=60, RightAmplitude=60, LeftFunction=WF_LinearIncreasing, RightFunction=WF_Constant, Duration=0.900)
		bIsLooping = true;
	End Object
	GamepadFeedback=RumbleFeedback
}

As you can see, my exec function check if the feedbackclass (manager) exists and then disable the current rumble and call a new one. The new rumble is defined in the default properties block. You can see all the settings possibles by looking inside the ForceFeedbackWaveform class. You can change the wave form to something like a sinusoidal for example. By default the feedback wave is limited in time, but I choose to loop it and use a timer to disable the rumble. Again, it was just for testing.

That’s all ! 🙂