Make Device stop when colliding with wall

I have a device that places a teleporter 800 units horizontally in front of the player character, no matter where the player looks. If the player activates a remote in their hand, they get teleported to the teleporters location. The problem with this is, that you can teleport yourself inside of walls and out of bounds because the teleporter clips through walls.


How can I make the teleporter stop when hitting a wall, even if the player moves closer to said wall? I don’t know if you can make a tracer that gets the object the player is looking at and calculate the distance between teleporter and player based on the objects location. Or is there a way to somehow enable collision for the teleporter?
Here’s the code I have so far:

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 we've created (TeleporterDevice)
    @editable
    Teleporter<public>: teleporter_device = teleporter_device{}

    PlaceNearPlayer()<suspends>: void =
        loop:
            if (PlayerList := GetPlayspace().GetPlayers(), FortniteCharacter := PlayerList[0].GetFortCharacter[]):
                PlayerRotation := FortniteCharacter.GetViewRotation()
                PlayerPosition := FortniteCharacter.GetTransform().Translation
                
                LocalForward := PlayerRotation.GetLocalForward()
                HorizontalForward := LocalForward - vector3 { Z := LocalForward.Z }
                
                TeleportDestination := PlayerPosition + HorizontalForward * 800.0
                
                TeleporterRotation: rotation = PlayerRotation

                Teleporter.MoveTo(TeleportDestination, TeleporterRotation, 0.001)
                #Print("Teleporting to: {TeleportDestination}")
            else:
                break
              
    OnBegin<override>()<suspends>: void =
        PlaceNearPlayer()

Any suggestions?

If you allow building or destruction, I don’t know of any solution.

If you don’t, what we did in our map is to tag all walls, and do a bit of math to identify whether the destination point will intersect with a wall. Something like this: graphics - How do you check for intersection between a line segment and a line ray emanating from a point at an angle from horizontal? - Stack Overflow

It is a huge pain though, especially if your boundaries are complex.

Hmm, random idea: you could try moving a perception device around, and seeing if player can still see the perception device. If they can’t, you could loop the perception device closer and closer, while also Await()-ing on the AgentLooksAtDeviceEvent, until player sees it: that would be a safe point for the teleporter.

1 Like

The idea with the perception device sounds really interesting, I didn’t think of that. I thought about using tags as well but like you said it’s a huge pain. I will give the perception trigger a try and if that doesn’t work I will experiment a bit with the tags. Thanks again for your advice on this project of mine! ^^