Make Teleporter move horizontally only

I made a device that puts a teleporter about 800 units in front of the player character and when the player activates the remote they are teleported to the teleporters location.

I want the teleporter to only move horizontally but I don’t know how I can access the yaw of the player rotation alone. Here’s my code:

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

# The device that spawns... campfire devices. <- how it started
teleport_positioner := class(creative_device):

    # Contains the teleporter prop-device (TeleporterDevice)
    @editable
    Teleporter<public>: teleporter_device = teleporter_device{}

    PlaceNearPlayer()<suspends>: void =
        loop:
            if (PlayerList := GetPlayspace().GetPlayers(), FortniteCharacter := PlayerList[0].GetFortCharacter[]):
                PlayerRotation: rotation = FortniteCharacter.GetViewRotation()
                PlayerPosition: vector3 = FortniteCharacter.GetTransform().Translation
                
                # Calculate the offset in the local space of the player
                OffsetInLocalSpace: vector3 = PlayerRotation.RotateVector(vector3{X := 800.0, Y := 0.0, Z := 0.0}) 
                
                # Calculate the position in front of the player
                TeleportDestination: vector3 = PlayerPosition + OffsetInLocalSpace
                
                # Calculate the rotation to face the player's view
                TeleporterRotation: rotation = PlayerRotation
                
                Teleporter.MoveTo(TeleportDestination, TeleporterRotation, 0.001)
                #Print("Teleporting to: {TeleportDestination}")
            else:
                break

    OnBegin<override>()<suspends>: void =
        PlaceNearPlayer()

Any suggestions?

I don’t know how I can access the yaw of the player rotation alone

One option is to use PlayerRotation.GetYawPitchRollDegrees() and then use MakeRotationFromYawPitchRollDegrees() but only pass in Yaw (element [0]).

Other option is to use ApplyPitch and ApplyRoll to reset those, but I don’t remember if the parameter replaces the current value, or if it adds to current value.

Third option is to eliminate Z from the vector instead, something like this:

PlayerRotation := FortniteCharacter.GetViewRotation()
PlayerPosition := FortniteCharacter.GetTransform().Translation

LocalForward := PlayerRotation.GetLocalForward()
HorizontalForward := LocalForward - vector3 { Z := LocalForward.Z }

TeleportDestination := PlayerPosition + HorizontalForward * 800.0
1 Like

That works, thank you very much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.