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: 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>