Skip to content

Commit

Permalink
Carrying - Limit walking speed (#91)
Browse files Browse the repository at this point in the history
Limit walking speed
  • Loading branch information
Kexanone authored Aug 6, 2024
1 parent 2397265 commit ba19797
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class ACE_Carrying_HelperCompartment : GenericEntity
protected SCR_CharacterControllerComponent m_CarrierCharCtrl;
protected static EPhysicsLayerPresets m_iPhysicsLayerPreset = -1;
protected static const int SEARCH_POS_RADIUS_M = 5; // Search radius for safe position for dropping carried player
protected static const float PRONE_CHECK_TIMEOUT_MS = 100; // Timeout for checking whether carrier tries do go prone
protected static const float HELPER_DELETION_DELAY_MS = 1000; // Delay for helper to get deleted after release
protected static const ref array<string> WALKING_INPUT_ACTION_NAMES = {"CharacterForward", "CharacterRight"};
protected static const float WALKING_INPUT_ACTION_LIMIT = 0.5;

//------------------------------------------------------------------------------------------------
//! Start <carrier> to carry the specified <carried>
Expand Down Expand Up @@ -78,13 +79,22 @@ class ACE_Carrying_HelperCompartment : GenericEntity
SCR_PlayerController carrierCtrl = SCR_PlayerController.Cast(GetGame().GetPlayerController());
ChimeraCharacter carrier = ChimeraCharacter.Cast(carrierCtrl.GetControlledEntity());
m_CarrierCharCtrl = SCR_CharacterControllerComponent.Cast(carrier.GetCharacterController());
GetGame().GetCallqueue().CallLater(PreventProneCarrier, PRONE_CHECK_TIMEOUT_MS, true);
SetEventMask(EntityEvent.FRAME);
}

//------------------------------------------------------------------------------------------------
//! Resets the stance if player attempts to go prone
protected void PreventProneCarrier()
//! Limit walking speed and prevent prone stance
override protected void EOnFrame(IEntity owner, float timeSlice)
{
super.EOnFrame(owner, timeSlice);

foreach (string actionName : WALKING_INPUT_ACTION_NAMES)
{
float value = GetGame().GetInputManager().GetActionValue(actionName);
GetGame().GetInputManager().SetActionValue(actionName, Math.Clamp(value, -WALKING_INPUT_ACTION_LIMIT, WALKING_INPUT_ACTION_LIMIT));
}

// Reset the stance if player attempts to go prone
if (m_CarrierCharCtrl.GetStance() == ECharacterStance.PRONE)
m_CarrierCharCtrl.SetStanceChange(ECharacterStanceChange.STANCECHANGE_TOCROUCH);
}
Expand Down Expand Up @@ -194,7 +204,7 @@ class ACE_Carrying_HelperCompartment : GenericEntity
if (carried)
carried.GetPhysics().SetInteractionLayer(m_iPhysicsLayerPreset);

GetGame().GetCallqueue().Remove(PreventProneCarrier);
ClearEventMask(EntityEvent.FRAME);
}

//------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit ba19797

Please sign in to comment.