在封裝手柄震動的介面,歸納下這方面的資料,
藍圖思路
內容界面右鍵Miscellaneous->Force Feedback Effect,創建力反饋物件并填寫相關引數:

然后在藍圖中用Spawn Force Feedback at Location呼叫這個力反饋組態檔,
或是創建Force Feedback組件,根據角色是否進入手柄震動區域來進行力反饋回應,
C++思路
C++部分的手柄力反饋,包括PS手柄的亮燈顏色等,都可以在PlayerController中直接設定,
APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0); if (PC)
{ FString path = "/Game/ThirdPersonCPP/NewForceFeedbackEffect.NewForceFeedbackEffect"; UForceFeedbackEffect* obj = LoadObject<UForceFeedbackEffect>(this, *path); PC->ClientPlayForceFeedback(obj); }
拿到力反饋組態檔丟給PlayerController執行即可,
順帶看了下PlayerController內部的呼叫邏輯,其內部好像走的是InputInterface:
IInputInterface* InputInterface = FSlateApplication::Get().GetInputInterface();
通過FSlateApplication拿到對應平臺的InputInterface,若使用該介面需加入Slate模塊的依賴,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/458394.html
標籤:其他
