Viveの利き手問題
現実の手について考えると、同じ作りなので、利き手による機能差の実装とかはいらなく、これは道具側に全処理を書けば良い話
ただ、ゲーム性としてこの道具と手の関係が省略されて、コントローラー固有の実装が乗ってくる可能性がある
こうなると、利き手変更機能が必要なので、VR開発の初期に作っておく
右利きかどうかのboolの変数つくっておいてBP内でbranchで分岐とかでも良さそうだけど、視覚的にめんどくさい事になりそうなのでInput自体を変更できたい
コントローラーのボタンの数だけInputを用意して、設定からこれを左右で反転できるようにする、となるとランタイムでInputを変更できるようにしないといけないので、それ用の関数を用意する
.h
public: UFUNCTION(BlueprintCallable, Category = "Input") static void AddAxisMapping(const FName axisName, const FKey key, const float scale); UFUNCTION(BlueprintCallable, Category = "Input") static void RemoveAxisMapping(const FName axisName, const FKey key); UFUNCTION(BlueprintCallable, Category = "Input") static void AddActionMapping(const FName actionName, const FKey key); UFUNCTION(BlueprintCallable, Category = "Input") static void RemoveActionMapping(const FName actionName, const FKey key); UFUNCTION(BlueprintCallable, Category = "Input") static void SaveKeyMappings(); UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Input") static FKey MakeKey(const FName name);
.cpp
void UBlueprintFunctionLibrary1::AddAxisMapping(const FName axisName, const FKey key, const float scale ) { const FInputAxisKeyMapping map(axisName, key, scale); GetMutableDefault<UInputSettings>()->AddAxisMapping(map); } void UBlueprintFunctionLibrary1::RemoveAxisMapping(const FName axisName, const FKey key) { const FInputAxisKeyMapping map(axisName, key, 0); GetMutableDefault<UInputSettings>()->RemoveAxisMapping(map); } void UBlueprintFunctionLibrary1::AddActionMapping(const FName actionName, const FKey key) { const FInputActionKeyMapping map(actionName, key); GetMutableDefault<UInputSettings>()->AddActionMapping(map); } void UBlueprintFunctionLibrary1::RemoveActionMapping(const FName actionName, const FKey key) { const FInputActionKeyMapping map(actionName, key); GetMutableDefault<UInputSettings>()->RemoveActionMapping(map); } void UBlueprintFunctionLibrary1::SaveKeyMappings() { GetMutableDefault<UInputSettings>()->SaveKeyMappings(); } FKey UBlueprintFunctionLibrary1::MakeKey(const FName name) { return FKey(name); }
この関数でイベントを作って、GameModeかどっかのBeginにも繋いでおく
同じようなイベントを左手用も作っておく、ゲーム開始時に変数を見てどっちかを実行する、またゲーム中にもこのイベントを実行すれば切り替わる
最後にSaveしておかないと、エディタを再起動するとSettings>Inputから消えてしまう、また一度SaveされたInputイベントはBPからも呼び出しできるので、先にInputでイベントを用意しておく必要もない
TriggerのScaleが0.6を超えると1.6になるのだけど、これはデフォの閾値設定みたいなやつっぽいので、うまいこと値は調節する
これを使ってついでにキーバインドのしくみもつくっておきたい、次回
追記: やった
miyahuji111.hatenablog.com
参考
Unreal Engine | FKey
Unreal Engine | FInputActionKeyMapping
Unreal Engine | FInputAxisKeyMapping
Bind keyboard and mouse input events dynamically - Epic Wiki
UnrealEngine4で2Dゲームを作ろう! その4 キーコンフィグ - GameProgrammar's Night