Jump to content
Sign in to follow this  
mrflay

Handling joystick/controller input events

Recommended Posts

Hi,

I'm wondering how to properly handle joystick/controller events from within a script. I would like to know when (for example) the player presses the "Forward" button and then handle/override the action with my own custom behavior.

This is for a hang gliding mod I'm working on. When the glider is on the ground and the player pushes "Forward", I need to trigger an animation and update the velocity to make it look like the player is carrying the glider.

I've got this working reasonably with keyboard input (see below), but I'm not sure how to support joystick or controller input (I don't own either a joystick or a controller).

// fn_ground.sqf
...
_KeyDownHandlerId = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call FLAY_HangGlider_EH_GroundKeyDown"];

// ev_groundKeyDown.sqf
...
_up = actionKeys "MoveForward";

_speedWalk = 2;
_speedRun = 6.5;
_maxSpeed = _speedWalk;

if (_running) then {
   _maxSpeed = _speedRun;
};

if (_key in _up) then
{
_anim = "AmovPercMwlkSnonWnonDf";
if (_running) then {
	_anim = "AmovPercMrunSnonWnonDf";
};

if (animationState player != _anim and _speed > 0) then {
	player playMoveNow _anim;
};

_k = 0.2;
if (_speed < 1.0) then {
	_k = 1.0;
};
if (_speed > _maxSpeed) then {
	_k = 0;
};
_glider setVelocity [(_v select 0) + _k * (_dir select 0), (_v select 1) + _k * (_dir select 1), (_v select 2) + _k * (_dir select 2)];
   _handled=true;
};

I'm assuming I should register joystickButton event handler, but how do I know when the button mapped to the "Forward" action is pressed?

Share this post


Link to post
Share on other sites

Actually this can be done without scripting. Look at some of the A3 configs to see how vehicle animations are linked to soldier animations. As far as I know, the joystick can only be read from within a display, at least that was the case in A2. I remember a hang gliding addon for OFP ten years ago that animated the guy as he ran haha.

Share this post


Link to post
Share on other sites
Actually this can be done without scripting. Look at some of the A3 configs to see how vehicle animations are linked to soldier animations.

I've looked at the configs, but don't really see anything that looks appropriate. Is there anything in particular I should look for?

Thanks!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×