一部の最も簡単な障害物は前後に動くだけです。 そのような障害物はプラットフォームの課題で出現することがよくあり、その場合はタイミングをとってジャンプし、落下しないように慎重に動かす必要があります。
そのようにプラットフォームを動かすことは平行移動と呼ばれ、オブジェクトのトランスフォームの位置を変更します。 このセクションでは、前後に動くだけでなく、ワールド内の複数のポイントに移動することができるプラットフォームを作成し、それらを使用して最初の障害物を作成する方法について説明します。
平行移動する小道具を作成する
以下の手順に従って、プラットフォームを平行移動するコードを作成します。
Verse Explorer を使用して、
translating_propを継承するanimating_propという新しい Verse クラスを作成します。 このクラスに<concrete>指定子を付加して、そのプロパティが UEFN に公開されるようにします。Verse# A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_prop<public> := class<concrete>(movable_prop):using { /Fortnite.com/Devices/CreativeAnimation }文とusing { /UnrealEngine.com/Temporary/SpatialMath }文をファイルの先頭に追加して、これらのモジュールがインポートされるようにします。 これらは、小道具をアニメートするために必要になります。 このセクションで使用されているツールチップも以下に示しています。Verseusing { /Fortnite.com/Devices } using { /Fortnite.com/Devices/CreativeAnimation } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } MovePositionTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget." # A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_prop<public> := class<concrete>(movable_prop):translating_propクラス定義の先頭に以下のフィールドを追加します。MoveTargetsという、creative_propの編集可能な配列。 これらは、ゲームプレイ中にRootPropの移動先となるクリエイティブの小道具です。 トランスフォームではない別の小道具を移動先のターゲットとして使用すると、小道具がどこに向かっているかを視覚化しやすくなります。 後でエディタで、ゲームプレイ中はこれらが見えないようにします。Verse# The Creative prop targets for the RootProp to move toward. @editable {ToolTip := MoveTargetsTip} var MoveTargets:[]creative_prop = array{}MovePositionという編集可能なvector3変数 (任意指定)。MoveTarget小道具が代入されていない場合、ルート小道具はこれを使用して移動先を把握します。Verse# The position for the RootProp to move toward. Use this if you # do not want to set a MoveTarget. @editable {ToolTip := MovePositionTip} var MovePosition:?vector3 = falseTargetPositionというvector3変数。 これは、小道具が実際に移動先とする位置であり、移動ターゲットの位置またはMovePositionのいずれかに設定されます。Verse# The position the prop is currently targeting. var TargetPosition:vector3 = vector3{}クラス定義は次のようになります。
Verse# A prop that moves (translates) toward either a Creative prop target # or a position in world space. translating_prop<public> := class<concrete>(movable_prop): # The Creative prop targets for the RootProp to move toward. @editable {ToolTip := MoveTargetsTip} var MoveTargets:[]creative_prop = array{} # The optional position for the RootProp to move toward. Use this if you # do not want to set a MoveTarget.
小道具を動かす
Move()関数をmovable_prop内でセットアップ済みであるため、このクラス内でそれをオーバーライドできます。translating_propクラスのMove()関数をオーバーライドします。Verse# Translate toward the MovePosition, or MoveTarget if one is set. Move<override>()<suspends>:void=Move()内のif式で、MovePositionが値NewPositionに設定および格納されているかどうかをチェックします。 設定および格納されていれば、TargetPositionをNewPositionに設定します。Verse# Translate the RootProp toward the MoveTarget, or MovePosition if one is set. Move<override>()<suspends>:void= # Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPositionMoveToEase()関数では、animation_modeが渡される必要があります。Move()が呼び出されるごとにアニメーションが一度再生され、アニメーションの終了時にどうなるかをanimation_modeが制御します。TargetPosition、MoveDuration、MoveEaseType、およびanimation_mode.OneShotを渡してMoveToEase()を呼び出します。 このアニメーション モードでは、オブジェクトがターゲットに到達するとアニメーションが停止します。 これは、以前にセットアップした、オーバーロードされたMoveToEase()関数であり、回転とスケールは受け取りません。Verse# Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition # Call MoveToEase to start moving the prop. The OneShot animation mode will play the animation once. RootProp.MoveToEase(TargetPosition, MoveDuration, MoveEaseType, animation_mode.OneShot)OneShot アニメーション モードは、オブジェクトをリセットする場合や、オブジェクトを移動し続ける場合に便利ですが、アニメーションを逆再生する場合はどうでしょうか。 その場合は、
PingPongアニメーション モードを使用できます。 このモードでは、アニメーションを再生した後に、小道具を逆向きに動かしてその開始位置に戻します。 また、Loopアニメーション モードもあります。このモードでは、アニメーションがループしますが、アニメーションは開始時と同じ位置で終了する必要があります。 体験のニーズに合うように、適切なアニメーション モードを選択します。小道具のセットアップ時に、エディタで
MovePositionを設定しなかった場合、ルート小道具が移動するには 1 つまたは複数のMoveTargetsを設定する必要があります。for式内でMoveTargetsを処理するには、MoveTargets配列内の各ターゲットをイテレートします。IsValid[]を呼び出して、MoveTargetが設定されているかどうかをチェックします。 設定されていれば、TargetPositionをMoveTargetの平行移動に設定します。Verse# Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition else: for: MoveTarget:MoveTargets do: # Set the TargetPosition to the MoveTarget's position if the最後に、今度はアニメーション モードに
animation_mode.OneShotを設定した状態で、MoveToEase()をもう一度呼び出します。 これをfor式内で行うと、それぞれのターゲットに小道具が順次移動し、設定されているパラメータに基づいて、終了時にリセットされるか、移動し続けます。 完成したMove()関数は次のようになります。Verse# Translate the RootProp toward the MoveTarget, or MovePosition if one is set. Move<override>()<suspends>:void= # Set the TargetPosition to the MovePosition if it is set. if: NewPosition := MovePosition? then: set TargetPosition = NewPosition # Call MoveToEase to start moving the prop. The OneShot animation mode will play the animation once.
Verse の仕掛けを構築する
ここまでで Verse コードが完成したので、それをレベル内で呼び出す方法が必要です。 別の Verse の仕掛けを使用して小道具を調整し、ゲームの開始時にそれらすべてをセットアップします。 以下の手順に従って、障害物を調整し、プラットフォームを動かします。
Verse Explorer を使用して、
prop_animatorという新しい Verse の仕掛けを作成します。 これは、小道具をあちこち動かすのを調整します。prop_animator内で、TranslatingPropsというtranslating_propの編集可能な配列を追加します。 そして、OnBegin()のfor式で、各小道具に対してSetup()を呼び出します。 完成したprop_animatorファイルは次のようになります。Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } TranslatingPropsTip<localizes>:message = "The props that translate (move) using animation." # Coordinates moving props through animation by calling each moveable_prop's Setup() method. prop_animator := class(creative_device): # Array of moveable_props that translate using animation.コードを保存してコンパイルします。
prop_animator仕掛けをレベルにドラッグします。
小道具を仕掛けに結び付ける
エディタに戻り、開始点付近の小道具をいくつか削除して、割れ目を作り出します。 2 つの FG01 Hover Platform M 小道具をレベルに追加します。 これらはアニメートするプラットフォームであるため、TranslatingPlatform という名前にします。 そして、いくつかの FG01 Button Bulb 小道具を追加します。これらは、各プラットフォームの移動先とするターゲットになります。 これらを PlatformTarget という名前にします。 割れ目の上にプラットフォームを配置し、プラットフォームの移動先とするターゲットを配置します。 各プラットフォームに対して複数のターゲットを指定できます。
小道具を平行移動するためのセットアップ。 各プラットフォームは、矢印で示されているように、2 つの移動ターゲット間で、前後に動きます。
ゲームプレイ中にターゲット小道具を非表示にする場合は、各ターゲットの [Rendering (レンダリング)] にある [Actor Hidden In Game (ゲームで非表示のアクタ)] を True に設定します。
prop_animator 仕掛けをレベルにドラッグし、選択します。 アウトライナーで、各プラットフォームで配列要素を TranslatingProps に追加します。 各小道具に以下の値を代入します。
| オプション | 値 | 説明 |
|---|---|---|
移動ターゲット | 小道具の移動先にするターゲットに代入します。 | これらは、順に小道具の移動先となるクリエイティブの小道具ターゲットである |
RootProp | アニメートしている小道具に代入します。 | アニメートしている小道具です。 |
[Launch Session (セッションを開始)] をクリックして、プラットフォームがアニメートされるのを確認します! MoveDuration、MoveEaseType、および開始遅延と終了遅延を変えて、さまざまなシナリオを試してみます。
平行移動は下向きであり、次のセクションでは、さまざまな方向に回転する小道具を作成します。
次
完全なコード
このセクションで作成した完全なコードを以下に示します。
translating_prop.verse
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/CreativeAnimation }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
MovePositionTip<localizes>:message = "The optional position to move to World Space. Use this if you do not want to set a MoveTarget."
# A prop that moves (translates) toward either a Creative prop target
# or a position in world space.
translating_prop<public> := class<concrete>(movable_prop):
prop_animator.verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
TranslatingPropsTip<localizes>:message = "The props that translate (move) using animation."
# Coordinates moving props through animation by calling each moveable_prop's Setup() method.
prop_animator := class(creative_device):
# Array of moveable_props that translate using animation.