# Calculating a rotation and using it in a function?

**URL:** <https://forums.unrealengine.com/t/calculating-a-rotation-and-using-it-in-a-function/1292843>\
**Category:** Verse\
**Tags:** rotation, unreal-editor-for-fortnite, fortnite-creative, function, question, fortnite\
**Created:** [September 12, 2023, 9:57pm UTC](https://forums.unrealengine.com/t/calculating-a-rotation-and-using-it-in-a-function/1292843 "2023-09-12T21:57:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexotronic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexotronic/32/469812_2.png) [@Alexotronic](https://forums.unrealengine.com/u/Alexotronic)\
**Post date:** [September 12, 2023, 9:57pm UTC](https://forums.unrealengine.com/t/calculating-a-rotation-and-using-it-in-a-function/1292843/1 "2023-09-12T21:57:53Z")

</div>

Hi all, I haven’t fully groked rotations and am hoping someone can easily point out the correct syntax.

Imagine a Square, and the player will TeleportTo a random side of the square when they take damage.

I was able to get location teleportation working, however I want the player to face the center of the square (‘MyProp’ location) on respawn.

My desire is to calculate the rotation and feed it into the TeleportTo function.

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

MyGameManager := class(creative_device):

    @editable
    MyProp : creative_prop=creative_prop{}

    var Players : []player = array{}

    RespawnLocations : []vector3 = array {vector3 {X:=0.0, Y:=-1536.0, Z:=50.0} , vector3 {X:=-0.0, Y:=1536.0, Z:=50.0} , vector3 {X:=-1536.0, Y:=-0.0, Z:=50.0} , vector3 {X:=1536.0, Y:=-0.0, Z:=50.0}}
    #A different approach: Instead of calculating rotation to center, make an array of transforms?
    #RespawnTransforms : []transform = array {} ...but how to hard code array of vectors + rotations?

    OnBegin<override>()<suspends>:void=
        AllPlayers := GetPlayspace().GetPlayers()
        for(Player : AllPlayers):
            AgentSetup(Player)
        GetPlayspace().PlayerAddedEvent().Subscribe(OnJoin)
 
    AgentSetup(Agent: agent):void=
        if(FortChar := Agent.GetFortCharacter[]):
            FortChar.DamagedEvent().Subscribe(OnDamaged)

    OnJoin(Agent: agent):void=
        AgentSetup(Agent)
        

    OnDamaged(DamageResult: damage_result):void=
        if:
            DamagedFortChar := fort_character[DamageResult.Target]            
                    DamagedFortChar.TeleportTo[RespawnLocations[GetRandomInt(0,3)], CalculateDesiredRotation()]
    
    CalculateDesiredRotation() : rotation =
        if(Player:= Players [0], FortniteChar := Player.GetFortCharacter[]):
            PlayerPosition := FortniteChar.GetTransform().Translation
            MyPropPosition := MyProp.GetTransform().Translation

            if (LookDirection := (MyPropPosition - PlayerPosition).MakeUnitVector[]):
                Yaw := RadiansToDegrees (ArcTan(LookDirection.Y,LookDirection.X))
                Pitch := RadiansToDegrees(ArcTan(LookDirection.Z, Sqrt((LookDirection.X * LookDirection.X)+(LookDirection.Y * LookDirection.Y))))
                Roll := 0.0

                NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw, Pitch, Roll)

        return NewRotation

```
