0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【UEFN】v39.00で追加されたfort_character の物理挙動APIに触ってみた(Velocity/Impulse/Force)

Last updated at Posted at 2025-12-01

v39.00で fort_character に物理挙動のメソッドが追加された

追加されたメソッドは下記の画像の通りです。
しかし、どんなものなのか自分には想像できなかった..!
この記事では、簡単なサンプルコードと実行結果を記載します。

image.png

環境: Fortnite v39.00 (UE 5.8)

物理挙動を変更する

サンプルコード全体

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

fort_character_test := class(creative_device):

    @editable
    Test1_Switch:switch_device = switch_device{}
    @editable
    Test2_Switch:switch_device = switch_device{}
    @editable
    Test3_Switch:switch_device = switch_device{}

    # レベル上に Verse Device 2つ配置して、TestPattern 1,2 と設定する
    @editable
    TestPattern:int = 1

    OnBegin<override>()<suspends>:void=
        for(Player : GetPlayspace().GetPlayers()):
            if(FC := Player.GetFortCharacter[]):
                FC.JumpedEvent().Subscribe(OnJumped)

    OnJumped(FC:fort_character):void=
        if(Agent := FC.GetAgent[]):
            if(Test1_Switch.GetCurrentState[Agent]):
                SetLinearVelocityTest(Agent)

            else if(Test2_Switch.GetCurrentState[Agent]):
                ApplyLinearImpulseTest(Agent)

            else if(Test3_Switch.GetCurrentState[Agent]):
                spawn:
                    ApplyForceTest(Agent)

    # -------------------------------------------------------
    # 1. SetLinearVelocity (速度の上書き)
    # -------------------------------------------------------
    SetLinearVelocityTest(Agent:agent):void=
        if(FC := Agent.GetFortCharacter[]):
            if(TestPattern = 1):
                Print("SetLinearVelocity: Up軸方向に 30m/s")
                FC.SetLinearVelocity((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=30.0, Forward:=0.0})

            else if(TestPattern = 2):
                Print("SetLinearVelocity: Forward軸方向に 30m/s")
                FC.SetLinearVelocity((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=0.0, Forward:=30.0})

    # -------------------------------------------------------
    # 2. ApplyLinearImpulse (瞬間的な衝撃)
    # -------------------------------------------------------
    ApplyLinearImpulseTest(Agent:agent):void=
        if(FC := Agent.GetFortCharacter[]):
            if(TestPattern = 1):
                Print("ApplyLinearImpulse: Up軸方向に瞬間的に 2000N*s")
                # GetLocalUpで上方向ベクトルを取得
                FCRot := FC.GetTransform().Rotation
                UpDirUE := FCRot.GetLocalUp()
                # Verse.org/SpatialMath モジュルの vector3 に変換
                UpDir := FromVector3(UpDirUE)
                FC.ApplyLinearImpulse(2000.0 * UpDir)

            else if(TestPattern = 2):
                Print("ApplyLinearImpulse: Forward軸方向に瞬間的に 2000N*s")
                FCRot := FC.GetTransform().Rotation
                ForwardDirUE := FCRot.GetLocalForward()
                ForwardDir := FromVector3(ForwardDirUE)
                FC.ApplyLinearImpulse(2000.0 * ForwardDir)

    # -------------------------------------------------------
    # 3. ApplyForce (継続的な力)
    # -------------------------------------------------------
    ApplyForceTest(Agent:agent)<suspends>:void=
        if(FC := Agent.GetFortCharacter[]):
            if(TestPattern = 1):
                Print("ApplyForce: Up軸方向に持続的な力 2000N")     
                for(I := 0..90):
                    FC.ApplyForce((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=2000.0, Forward:=0.0})
                    Sleep(0.033)

            else if(TestPattern = 2):
                Print("ApplyForce: Forward軸方向に持続的な力 2000N")       
                for(I := 0..90):
                    FC.ApplyForce((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=0.0, Forward:=2000.0})
                    Sleep(0.033)

プレイヤーがジャンプしたときに、Switch Device をチェックして、ON になっているメソッドを実行するようにしています。

SetLinearVelocity

コード

SetLinearVelocityTest(Agent:agent):void=
    if(FC := Agent.GetFortCharacter[]):
        if(TestPattern = 1):
            Print("SetLinearVelocity: Up軸方向に 30m/s")
            FC.SetLinearVelocity((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=30.0, Forward:=0.0})

        else if(TestPattern = 2):
            Print("SetLinearVelocity: Forward軸方向に 30m/s")
            FC.SetLinearVelocity((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=0.0, Forward:=30.0})

プレイ動画

発見
・グローバル座標で動く

ApplyLinearImpulse

コード

ApplyLinearImpulseTest(Agent:agent):void=
    if(FC := Agent.GetFortCharacter[]):
        if(TestPattern = 1):
            Print("ApplyLinearImpulse: Up軸方向に瞬間的に 2000N*s")
            # GetLocalUpで上方向ベクトルを取得
            FCRot := FC.GetTransform().Rotation
            UpDirUE := FCRot.GetLocalUp()
            # Verse型に変換してApplyLinearImpulseに渡す
            UpDir := FromVector3(UpDirUE)
            FC.ApplyLinearImpulse(2000.0 * UpDir)

        else if(TestPattern = 2):
            Print("ApplyLinearImpulse: Forward軸方向に瞬間的に 2000N*s")
            FCRot := FC.GetTransform().Rotation
            ForwardDirUE := FCRot.GetLocalForward()
            ForwardDir := FromVector3(ForwardDirUE)
            FC.ApplyLinearImpulse(2000.0 * ForwardDir)

プレイ動画

発見
・ローカル座標で動く

ApplyForce

ApplyForceTest(Agent:agent)<suspends>:void=
    if(FC := Agent.GetFortCharacter[]):
        if(TestPattern = 1):
            Print("ApplyForce: Up軸方向に持続的な力 2000N")     
            for(I := 0..90):
                FC.ApplyForce((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=2000.0, Forward:=0.0})
                Sleep(0.033)

        else if(TestPattern = 2):
            Print("ApplyForce: Forward軸方向に持続的な力 2000N")       
            for(I := 0..90):
                FC.ApplyForce((/Verse.org/SpatialMath:)vector3{Left:=0.0, Up:=0.0, Forward:=2000.0})
                Sleep(0.033)

プレイ動画

発見
・グローバル座標で動く
・繰り返している間だけ移動が継続する

参考

Unity にも同じような機能があるんですね。参考になりました

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?