2D Character teleports in only one direction

So I’m having an issue where my character will only go towards the X axis in the positive direction when teleporting and when the character is turned around it won’t switch to that direction. How would I fix this?

Hi oldsiren,

Currently your teleport is set to only go one direction, There are a number of ways to do this. The first is to get the player’s forward vector and rotate the additional x value (using a rotate vector) , add it to the forward vector, and use that as the dest location. The other method would be to do a branch that checks if the player’s forward vector is positive or negative x, then you simply set the dest location to + or - x value based on this information.

If I was to use the branch method, how would I set up the check with the forward vector? I have the dest location setup but I don’t know about what would check the forward vector’s positive or negative X?

I thought about it a bit more, instead of checking the forward vector, check the player character’s rotation by using a “get actor rotation” or “get actor world rotation” node with a target of the character (or self if the code is in the character blueprint). After this, you can check to see if the rotation is > or < 0, if it is < 0, you must be facing the negative X value so you should be able to set the location value to negative. If > 0, then the player must be facing the positive value and so you should use a positive location value.

What would be the node that checks if it is > or < 0 and setting the location value’s? I’m sorry if this seems a little bit annoying. I’m rather new to Unreal and Game Development in general.

I decided to play around with this a bit and came up with a potential solution. You can still use the teleport node though more often than not I don’t recommend it. Instead, I would use a set actor relative location node and use a setup similar to the following:

In this, I check the players rotation to see if it is 0, > 0, or < 0. In the case of the base 2D example you can typically just check for 0 or < 0, but I chose to do > as well as a safety net of sorts. Once I determine this I either set the new actor location to actorlocation + teleport distance (1000) or actorlocation + (-teleport distance) as appropriate. It is important to check sweep to true on the set actor relative location, as what this does is check the new spawn location for other actors. If one with collision is hit, it will place the character at the next acceptable location between the player and the object.

Thank you soo much, apologies for the long reply but I would also like to ask a different topic question specifically to you or somebody who is qualified for this question, (because your a part of the staff which is what I’ve been trying to reach for this question) where would I go to or whom would I have to reach to ask this?