Teleporting Object In Game Glitch

I am adding borders to the edges of the game area, where once a player or enemy touches it, they get teleported to the opposite side of the game area.

I have it coded where when the pawn begins a collision with a Border actor, it is moved to the other side using “Set World Location.” Each Border actor has a variable to determine whether it is the border on the left or the border on the right. This is what it looks like:

I also have an Enemy actor which does the same thing (sets its world location to the opposite side when it touches a border)

However, when I test it out in game, it glitches and gets stuck in a loop of going back and forth, like this:
Untitled design (1)

Some extra info:
The pawn is moved by adding an impulse when the player presses down on the A or D keys. Meanwhile, my Enemy actor sets a new world location for itself on every tick. Could this impulse be the root of the problem, and if so, how could I fix it? I have already tried setting the pawn’s velocity to 0 when it touches a border, as to avoid any impulse problems, but it still resulted the same.

Whenever the pawn touches the Enemy, it “respawns” to the middle of the game area. That is what stops the glitching sometimes, as you can see that it prints “hit by enemy.”

Hey @fbcoyote!

You can add a Do Once right after your begin overlap node, then get an end overlap node and connect it to the Reset input exec pin of our Do Once node.

(Additionally, you might wanna use an Is Valid? node and connect the Other Actor to it’s input pin, and then check if the actor is indeed the actor that you’re gonna cast to by either checking it’s display name or by adding an actor type tag to it and checking that. This recommendation isn’t related to your current issue tho, it’s to prevent potential issues you might encounter in the future.)

Hope this helps :innocent:

1 Like

Hello! Sorry for the late response.

Here is how I added this to my code:

It’s only allowing me to add one image, so I will continue in the next reply.

This seems to have broken the border for my pawn, so the border has no effect on it. However, the border still works for my Enemy actor. Here is what happens:
Untitled design (2)

Hey @fbcoyote!

Here’s how to set up your objective from scratch:

  • Create a new actor for our borders and add a box collision component to it.

  • Place our border actor into the level 2 times, one at the left border and one at the right border.

  • While having the left one selected, navigate to the Details window at the bottom left (below the Outliner window and next to the World Settings window), type in “tag” into the search bar, and under Actor > Advanced > Tags, create a new tag and name it “Left” like this:

Also do the same for the right one but name it’s tag “Right”.

  • Head to the project settings, type in “channel” into the search bar, and under Trace Channels, create a new channel and name it “Border” like this:

If it’s default response is set to Block, there’s no need to adjust our border actor’s collision settings as it would already block our new trace channel. But that would require you to adjust the collision settings of all the other obstacles in your level, setting them to ignore the new trace channel. On the other hand, if you set it’s default response to Ignore, you’d only need to adjust our border actor’s collision settings to make it block the new trace channel.

  • Finally, inside the Event Graph of your player pawn (or character), implement this blueprint code:

And here’s the result:

Hope this helps! :blush:

Hey @fbcoyote! It’s been a while since we last heard from you. Do you have any updates?

Hello! Sorry for the late reply.
I implemented this code, but it does not seem to be 100% working. It doesn’t work at all for my enemies, but it sometimes works for my pawn. Here is a video of the different things that happen:
new solution trials

(Continuing in a reply because I can only embed one file per post)

Everything is exactly as you said to put it, except for the Border trace channel. I decided to set it to Ignore and then edit the border actor’s collision settings. This is what my border actor’s collision settings are set to:

(Continuing in a reply because I can only embed one file per post)

And this is what my pawn and enemy actor’s collision settings are set to:

Again, sorry for the late reply and thank you for your help!

Just to make sure, could you provide a screenshot of your blueprint code?

Also in your next reply, could you include some of your findings upon further debugging such as:

  • The line trace hit location (You can draw a debug sphere to visualize)

  • The result of our Add node that we plug into the New Location Y pin (Your orientation might be different, you might need to subtract from Y instead of adding, or add / subtract to / from the Impact Point X)

Speaking of orientation, whether to assign 1 or -1 to right or left also depends on it! As well as whether to use the actor right vector, negated actor forward vector, actor forward vector, or negated actor forward vector.

  • The execution flow, to see if the begin & end overlap events get triggered as expected, which you can debug by placing breakpoints after our Do Once node and before resetting it, or by placing Print String nodes on the said parts

Additionally, could you share screenshots confirming that:

  • The component reference we plug into the Get World Scale node is your static mesh

  • You indeed have a single actor BP for our borders, which you placed 2 times into your level, and each have different actor tags assigned to them

  • Your actor doesn’t rotate towards the direction it’s moving to, which you can showcase & also see it yourself by creating a new arrow component for it, and unchecking it’s Hidden in Game property

Good luck :smiling_face_with_three_hearts: