I want to give my players the ability to teleport a short distance. The idea is they could use the teleport to avoid incoming objects. Right now I am creating a trace line, finding the end point, and teleporting the actor to that location with “Set Actor Location”
My problem is I can either:
A) Teleport directly to the end of the trace point, often ending up with me inside of an object and getting trapped.
OR
B) I have “Sweep” turned on, which teleports my along my trace line until it collides with an object. So I always stop right before I would be colliding with the object in my way. Which doesn’t help when you’re using the teleport to AVOID objects.
I need a way to combine the functionality of both A and B so that I can cast a trace line, determine weather or not the end point is colliding with something, If NO I want to teleport to that point, if yes, I want to teleport just before reaching the object.
Not sure if its the most efficient way to do it, but what I would do is when you run the ray trace, store a variable of the location that you want to travel to and then break the ray trace “hit” and do a quick check to see if there is another actor or actor component anywhere along that trace and if so, then get its location and set your characters location to equal that location, but add a vector to that actors location and just increase along anyone of the three axis. Essentially what that would be doing, is running a trace to the location you want to travel too and then if there is an object in the way, just teleport your character just a little further past the colliding actor, simulating the effect of teleporting through it.
You can get this effect if you put down a nav mesh and use the node Project Point TO Navigation. This will cause you to teleport to the closest free space to the end point of your teleportation vector.
You do not need a line trace for this. Just save a vector variable that points to the teleportation location. Then feed that vector into the node I mentioned above. Then teleport as per normal, without sweep.
This will not work since you do not know the extent of the object. If you did the math to compute that you would still be able to go through a mile long object. If you are going to consider that and program around it I would simply use a nav mesh bounds.
My game is top down twin stick shooter so I’m casting the ray from my characters chest in the direction that they’re moving. The problem is the line traces straight out, not out and down. So I can’t check if I hit an up facing normal, as the line never hits the ground.
Is there any way I can use this same solution while casting the line from the characters forward vector?
You can simply take the vector returned by the node I talked about. That vector points to a walkable area that is almost guaranteed to have a normal pointing up. If you want to make sure, however, you can simply do another linetrace from you to this new location and check the vector there. The navmesh vector that you get when projecting is always at ground level, so you will always hit the ground with that linetrace.
Another solution is to do a linetrace straight down from the end of your previous linetrace and check that normal.