Get Single Float of Vector3

I’m using the GetTransform().Translation to get the vector3 of the player position and adding the player view location to make the prop spawn in front of the player, where they’re looking.
I still want to keep the y and z position of the GetTransform().Translation, but want to use a Y position of 0, so the prop always spawns on the ground.

Any help is appreciated!

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

tower_placing := class(creative_device):

    @editable Tower : creative_prop_asset = DefaultCreativePropAsset

    @editable InputTriggerPlaceTower : input_trigger_device = input_trigger_device{}

    OnBegin<override>()<suspends>:void=
        InputTriggerPlaceTower.PressedEvent.Subscribe(SpawnMesh)

    SpawnMesh( Agent : agent ) : void =
        if (FortCharacter := Agent.GetFortCharacter[]):
            PlayerPos := FortCharacter.GetTransform().Translation
            PlayerForward := FortCharacter.GetViewRotation().GetLocalForward() * 300.0
            PropSpawnPos := PlayerPos + PlayerForward
            NewPropSpawn := vector3{X := PropSpawnPos, Y := 0.0, Z := PropSpawnPos} 
            #ERROR for PropSpawnPos in Vector3: 
            # This variable expects to be initialized with a value of type float, 
            # but this initializer is an incompatible value of type vector3
            
            SpawnProp(Tower, NewPropSpawn, rotation{})

            Print("Player Pos: {PlayerPos}")
            Print("Prop Spawn Loc: {PropSpawnPos}")

You need to give the X to the X and the Z to the Z. This way, you are assigning the whole coordinates to the X and Z.
Try this way:
NewPropSpawn := vector3{X := PropSpawnPos.X, Y := 0.0, Z := PropSpawnPos.Z}

Also, just know that if you want it to always have the same height, you have to set the Z (which is the height in UE5) to 0.0 and not the Y.

1 Like

Thanks this worked for me!

1 Like

Nice! be sure to mark this topic as solved (click on 3 dots of my answer) so others won’t need to open it!

When clicking the 3 dots I can like the post, copy the link, report, bookmark and reply. It doesn’t show a set as solution button anymore…

By the way, do you happen to know how to break a loop when an event has happened (button interaction for example)

Oh maybe you created a topic instead of a question, np

you just write

break

whenever you want it to break the loop

Yes I know, but I want the loop to keep looping until a button is pressed.

    SelectTower(Agent:agent):void=
        if (FortCharacter := Agent.GetFortCharacter[]):
            loop:
                PlayerPos := FortCharacter.GetTransform().Translation
                PlayerForward := FortCharacter.GetViewRotation().GetLocalForward() * 300.0
                PropSpawnPos := PlayerPos + PlayerForward
                NewPropSpawn := vector3{X := PropSpawnPos.X, Y := PropSpawnPos.Y, Z := 0.0} 
                SpawnProp(Tower, NewPropSpawn, rotation{})
                    if (InputTriggerPlaceTower.PressedEvent.Await()):
                        break

Then you have to create a var of type logic, and set It on true when you press the button.
Then, put an if in the loop and if the var is true you break