Verseメモ – プレイヤー情報を取得する[UEFN,Verse]

目次

参考サイト

  • 公式ドキュメント

プレイヤー情報を取得する

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Characters }

get_all_players_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Playspace: fort_playspace = GetPlayspace()
        AllPlayers: []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):

それぞれの行を確認

Playspace: fort_playspace = GetPlayspace()
  • プレイヤーを取得するために必要な関数「GetPlayspace()」を呼び出して「fort_playspace」型の定数に入れる。
using { /Fortnite.com/Playspaces }
  • 「fort_playspace」を使用するには「using { /Fortnite.com/Playspaces }」を冒頭に記述する必要があるので追記する。
AllPlayers: []player = Playspace.GetPlayers()
  • 全てのプレイヤーを取得する関数GetPlayers()を呼び出す。
  • GetPlayersはplayer型の配列を返すので、player型の配列のAllPlayers定数に入れる。
if (FirstPlayer : player = AllPlayers[0]):
  • AllPlayers定数に入れたプレイヤー情報の配列の先頭に変数があるかチェックする。
  • 変数があればその値をplayer型の定数FirstPlayerに入れる。
if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
  • GetFortCharacter[]を呼び出して定数FirstPlayerの情報がフォートナイトのキャラクターであるかどうかチェックする。
  • フォートナイトのキャラクターであればその値をfort_character型の定数FortniteCharacterに入れる。
  • このfort_character型の定数FortniteCharacteを取得できたので、いろいろなメソッドを呼びだすことができる。
using { /Fortnite.com/Characters }
  • fort_characterを使用するために「using { /Fortnite.com/Characters }」を冒頭に追記する。

fort_character interface

  • 公式ドキュメント
  • キャラクターにダメージを与えたり回復したり、位置情報を取得したりできる・・のかな。

キャラクターにダメージを与える

FortniteCharacter.Damage(50.0)
  • fort_character型の定数FortniteCharacteのDamage()を使用する。
  • ゲームを開始するとキャラクターがダメージを受ける。

キャラクターを回復する

FortniteCharacter.Damage(50.0)
Sleep(2.0)
FortniteCharacter.Heal(30.0)
  • Heal()を使用する。
  • ダメージを受けた2秒後に回復させる。
  • ダメージを受けた後の2秒後に回復したのでよし。

キャラクターの位置情報などを取得する

using { /UnrealEngine.com/Temporary/SpatialMath }
  • 必要だったので冒頭に追記。
Location := FortniteCharacter.GetTransform().Translation
Print("{Location}")

Rotation := FortniteCharacter.GetTransform().Rotation
Print("{Rotation}")

Scale := FortniteCharacter.GetTransform().Scale
Print("{Scale}")
  • GetTransform()を呼び出す。
  • Location,Rotation,Scaleが取れるようなのでそれぞれ取得して画面表示させてみる。
  • 公式ドキュメント

ゲーム開始後に動いた場所で取得してみる

  • ミニマップでの表示。
  • 矢印がキャラクターの位置と向きを表している。
  • 1マスが500みたい。
  • Zが77なのはその高さがキャラクターの中心ということか。
  • マップ表示での北を向いた場合のAngleはだいたい0。
  • x軸はマップの北方向がプラス。y軸は東方向がプラス。
  • 南を向いた場合のAngleはだいたい180。

今回のVerseコード

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Playspaces }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }

get_all_players_device := class(creative_device):

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Playspace: fort_playspace = GetPlayspace()
        AllPlayers: []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Damage(50.0)

                Sleep(2.0)
                FortniteCharacter.Heal(30.0)

                Location := FortniteCharacter.GetTransform().Translation
                Print("{Location}")

                Rotation := FortniteCharacter.GetTransform().Rotation
                Print("{Rotation}")

                Scale := FortniteCharacter.GetTransform().Scale
                Print("{Scale}")

コメント

コメントする

目次