Check for collision before teleporting.

Hi!

First post here on the forum!
Gonna try to describe this as best I can.

What I’ve got:
I’m working on a 2D game. The character is moving 1 unit per frame along the X axis. The main camera isn’t attached to the character itself but handled by a different blueprint. That blueprint consists of a collision box and a camera. That blueprint is also moving with the same speed, 1 unit per frame. The character can teleport (Using SetActorTransform) 32 units per pressed key using WASD. The characters collision capsule is set to no collision, but query only and thus can fire overlap events. If the character is colliding with an object on the tilemap, it’s speed is set to 0 units per frame. The character then stops, but the blueprint with the collision box and camera is still moving 1 unit per frame. Meaning that if the player doesn’t move the character out of the way of the object, the character is pushed out of the screen. If this happens, the player dies and the level restarts.

What I want to do:
I can still teleport through walls. I want to check what my next position will be, and if there is collision only move up until the point of collision and obviously not through walls. As I mentioned previously the teleporting is handled by SetActorTransform and simply adding/subtracting 32 units to the actors current transform.

I hope this post isn’t too confusing. I can provide some screenshots later today if that helps!
Thanks!

Set up a raytrace (Line Trace by Channel) and get the Impact Point. Teleport to that or the location, whichever is closer.

Why don’t you use capsule trace?

Thanks for responding!

I’m trying out the CapsuleTrace. I can see from the Draw Debug that the trace is actually working. However, the character teleports to 0.0.0.
Don’t really know what I’m doing wrong here. I’m uploading a part of the character blueprint.

EDIT: I figured it out! If the Return Value from the Trace is false, the Hit Impact Point is 0.0.0. Rookie mistake I guess :). Thanks for the help!