When teleporting character, character often teleports to the wrong location

Hello there,
I have a problem with my teleportation script. Here it is:

So, when I click ‘F’, I normally teleport to where I am looking. Occasionally though, I teleport to the wrong location, but it is always the same location, not just some random location. I have tried using both a ‘teleport’ node and a ‘set actor location’ node. Both yield the same result. The variables and flip flop are just for the animations I made. I have set it up so that you click ‘F’ once to aim, and then click it again to teleport.

Link to a video of the error occurring:
[Click here][2]

Help is much appreciated.

Have you checked to see if the place it teleports you to is vector 0, 0, 0? I had this problem when I implemented my blink spell. In my case I fixed it by doing a check on the location pin from the Break Hit Result. If it is equal to 0, 0, 0, then I do not let the player teleport.

No, I don’t believe it is. Even if it was, then your solution would make it so it would not teleport if the error occurred, which would be just as annoying. Any other ideas?

I just dont understand why you are taking WorldRotation of your camera and after that a forward vector. Just forward vector isn’t enought?

But about this error, LineTraceByChannel returns bool value, it shows if there was collision or not. It can simply happend that you dont have a point in 2000 units forward so it will teleport you to wrong direction.

My suggestion: check the return value from LineTrace, if there is a collision teleport to location from HitResult, if not teleport to location pinned to End slot in LineTraceByChannel node.

The rotation of the camera means that a line is traced from where the camera is looking, and thus where the character is looking.

In my case it was okay to stop the player from teleporting since I am replicating the blink spell from WoW which also sometimes did not teleport in rough terrain. Some things you might try are replacing the line trace with a capsule trace, enabling trace complex, and adding code on the hit actor result that verifies the location to teleport is valid. I watched the video and was not able to see what you mean when you say it always teleports to the same place.

Turns out the location the character is teleporting to is 0 on the X and Y axis, but not on the Z axis. Either way, I’ll see if using the capsule trace works.

I figured out what was going wrong. When I was doing the trace, I multiplied the forward vector by around 2000 to get a line that long. When I aimed at a location further than that away, the line trace could not go that far, and thus never hit anything. When I teleported to the hit location, it teleported me to 0,0 in terms of x and y, as there was no hit. Changing the multiplication float to a large number such as 50000 solved the issue.

That is exactly what I wrote as answer 4 days before you figured it out :slight_smile: