I have a anti-gravitation-elevator in my game - as soon as the player enters the trigger, the ability starts.
Using the DetectObject ability works fine. I also managed that the player kind of get dragged to the XZ-center (or horizontal center) of my elevator,
so the ability is working and enabled.
Now I want to use the Jump & Crouch Buttons to make the character float upwards and downwards while inside the elevator but it seems to ignore my inputs.
I had a look at the "New Ability" Example from the documentation, but inputs are not mentioned there.
Also I saw that inputs usually start or stop abilities, which is not the case here - a trigger starts the ability, user then controlls upward & downward movement.
Long story short, code is below, and despite the ability being (active) the fields "bool liftUp" and "bool liftDown" always stay "false" no matter what Buttons I press.
Also I feel like there should be an easier way to get inputs, without having to write so many boilerplate code? IDK - seems like I am doing something wrong here.
Using the DetectObject ability works fine. I also managed that the player kind of get dragged to the XZ-center (or horizontal center) of my elevator,
so the ability is working and enabled.
Now I want to use the Jump & Crouch Buttons to make the character float upwards and downwards while inside the elevator but it seems to ignore my inputs.
I had a look at the "New Ability" Example from the documentation, but inputs are not mentioned there.
Also I saw that inputs usually start or stop abilities, which is not the case here - a trigger starts the ability, user then controlls upward & downward movement.
Long story short, code is below, and despite the ability being (active) the fields "bool liftUp" and "bool liftDown" always stay "false" no matter what Buttons I press.
Also I feel like there should be an easier way to get inputs, without having to write so many boilerplate code? IDK - seems like I am doing something wrong here.
C#:
private UltimateCharacterLocomotionHandler m_Handler;
[SerializeField] string liftUpInputName = "Jump";
[SerializeField] string liftDownInputName = "Crouch";
ActiveInputEvent _liftUpStart;
ActiveInputEvent _liftUpEnd;
ActiveInputEvent _liftDownStart;
ActiveInputEvent _liftDownEnd;
[SerializeField] bool liftUp;
[SerializeField] bool liftDown;
public override void Awake()
{
base.Awake();
m_Handler = m_GameObject.GetCachedComponent<UltimateCharacterLocomotionHandler>();
}
protected override void AbilityStarted()
{
base.AbilityStarted();
if (m_Handler != null && InputIndex != -1)
{
_liftUpStart = ObjectPool.Get<ActiveInputEvent>();
_liftUpStart.Initialize(ActiveInputEvent.Type.ButtonDown, liftUpInputName, "OnLiftUpStart");
m_Handler.RegisterInputEvent(_liftUpStart);
EventHandler.RegisterEvent(m_GameObject, "OnLiftUpStart", OnLiftUpStart);
_liftUpEnd = ObjectPool.Get<ActiveInputEvent>();
_liftUpEnd.Initialize(ActiveInputEvent.Type.ButtonUp, liftUpInputName, "OnLiftUpEnd");
m_Handler.RegisterInputEvent(_liftUpEnd);
EventHandler.RegisterEvent(m_GameObject, "OnLiftUpEnd", OnLiftUpEnd);
_liftDownStart = ObjectPool.Get<ActiveInputEvent>();
_liftDownStart.Initialize(ActiveInputEvent.Type.ButtonDown, liftDownInputName, "OnLiftDownStart");
m_Handler.RegisterInputEvent(_liftDownStart);
EventHandler.RegisterEvent(m_GameObject, "OnLiftDownStart", OnLiftDownStart);
_liftDownEnd = ObjectPool.Get<ActiveInputEvent>();
_liftDownEnd.Initialize(ActiveInputEvent.Type.ButtonUp, liftDownInputName, "OnLiftDownEnd");
m_Handler.RegisterInputEvent(_liftDownEnd);
EventHandler.RegisterEvent(m_GameObject, "OnLiftDownEnd", OnLiftDownEnd);
}
// Reset the accumulated gravity
m_CharacterLocomotion.GravityAmount = 0;
}
void OnLiftUpStart() { liftUp = true; }
void OnLiftUpEnd() { liftUp = false; }
void OnLiftDownStart() { liftDown = true; }
void OnLiftDownEnd() { liftDown = false; }