Action Handler C# Help

#1
I've tried to set up an action handler in C# to take input from an xml file... However it does not work for some reason...

Code for the entity component that I have attached to an entity:

Code: Select all

//Variables private const string actionMapUrl = @"Libs/config/defaultprofile.xml"; private const string actionMapName = "player"; private ActionHandler actionHandler; protected override void OnGameplayStart() { base.OnGameplayStart(); InitializeInput(); } //INPUT private void InitializeInput() { actionHandler?.Dispose(); actionHandler = new ActionHandler(actionMapPath: actionMapUrl, actionMapName: actionMapName); actionHandler.AddHandler("moveforward", OnMoveForward); } private void OnMoveForward(string name, InputState state, float value) { if (state == InputState.Changed) Entity.Physics.Velocity += new Vector3(0, 0, 100); }
Code in the xml file (same as the xml in the fps template:

Code: Select all

<profile version="0"> <platforms> <PC keyboard="1" xboxpad="1" ps4pad="1"/> <XboxOne keyboard="1" xboxpad="1" ps4pad="0"/> <PS4 keyboard="1" xboxpad="0" ps4pad="1"/> </platforms> <!--DO NOT REMOVE DEFAULT ACTIONMAP! NEEDED BY CRYACTION.--> <actionmap name="default" version="1"/> <!----> <actionmap name="player" version="1"> <action name="moveleft" onPress="1" onRelease="1" retriggerable="1" keyboard="a"/> <action name="moveright" onPress="1" onRelease="1" retriggerable="1" keyboard="d"/> <action name="moveforward" onPress="1" onRelease="1" retriggerable="1" keyboard="w"/> <action name="moveback" onPress="1" onRelease="1" retriggerable="1" keyboard="s"/> </actionmap> </profile>

Re: Action Handler C# Help

#2
Normal buttons and keys send Pressed, Down and Released events. But Changed is only sent by analog-events, such as the mouse or analog-sticks on a controller.
So in your case you probably want to listen to the Pressed and Released events instead.
Example from the Third Person Template:

Code: Select all

if(state == InputState.Pressed)
{
_movement.Y = 1.0f;
}
else if(state == InputState.Released)
{
//The movement only needs to be stopped when the player is still moving forward.
if(_movement.Y > 0.0f)
{
_movement.Y = 0.0f;
}
}

Who is online

Users browsing this forum: No registered users and 0 guests

cron