UE5增强输入持续游戏手柄摇杆绑定

问题描述 投票:0回答:1

我想要的行为是游戏手柄左摇杆 2d 向量将在其最新位置的每个刻度处发送输入,无论它是四处移动还是已返回到 0。

  • 当我
    EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started ...
    时,每次摇杆移动超过驱动阈值时,我都会收到 1 个事件 - 不太酷,因为当摇杆位置发生变化或返回到 0 时,我不会收到更多事件
  • 当我
    EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Ongoing ...
    时,我根本没有收到任何事件。

Input Mapping Context

Input Action

input unreal-engine5 gamepad unreal enhanced-input-system
1个回答
0
投票

自定义输入触发器和修改器累积

Content Browser: Custom Input Mapping Context

Content Browser: Custom Input Action

IA_ShipMove

UInputTriggerChordTicking.h

#pragma once
#include "InputTriggers.h"

#include "UInputTriggerChordTicking.generated.h"

UCLASS()
class UInputTriggerChordTicking : public UInputTriggerChordAction
{
    GENERATED_BODY()

public:
    UInputTriggerChordTicking();
};

UInputTriggerChordTicking.cpp

#include "Input/UInputTriggerChordTicking.h"

UInputTriggerChordTicking::UInputTriggerChordTicking()
{
    bShouldAlwaysTick = true;
}

UInputModifierAccumulated.h

#pragma once
#include "InputModifiers.h"

#include "UInputModifierAccumulating.generated.h"

UCLASS()
class UInputModifierAccumulating : public UInputModifier
{
    GENERATED_BODY()
 
public:
    virtual FInputActionValue ModifyRaw_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue CurrentValue, float DeltaTime) override;
 
protected:
    float AccumulatedValue = 0;
};

UInputModifierAccumulated.cpp

#include "Input/UInputModifierAccumulating.h"

FInputActionValue UInputModifierAccumulating::ModifyRaw_Implementation(const UEnhancedPlayerInput* PlayerInput, FInputActionValue CurrentValue, float DeltaTime)
{
    const float CurrentFloat = CurrentValue.Get<float>();
    AccumulatedValue += CurrentFloat;
    
    return FInputActionValue(AccumulatedValue);
}
© www.soinside.com 2019 - 2024. All rights reserved.