How do I teleport my player without getting stuck in walls?

  • Hello, I'm having a weird issue that maybe you might be able to help with. My game is a top-down space shooter, and I'd like one of the player's abilities to be a sort of "blink" teleport, where you jump a bit ahead in whatever direction you're moving. That part I was able to get down just fine and in open space it works perfectly just like this:

    But the problem I'm having now is, I don't know how to confine the player's teleporting to the playable area. Here's a rudimentary doodle as an example (the black part is the wall of the playable area).

    Right now what happens when the player blinks is this:

    The ship goes inside the wall and just gets stuck there. What I'd like to happen is something like this:

    The player stays outside the wall and only teleports as far as they can go before going inside it. How would I go about coding something like this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Maybe use an invisible sprite to represent possible teleport locations and test collisions on that? You could give it an incredibly fast bullet behavior so that when the player presses the keys to teleport, the tester sprite shoots out into position, either gets stopped by a wall or doesn't, and then set the player's position to that of the tester.

    I'm sure there is a more elegant idea than that but it's late here and that's all I got

  • That worked, thank you! Very rarely, the invisible super-speed bullet will phase through the wall due to collision wonkiness and I'll end up with the same problem, but I think it's just a matter of finding the right size for the bullet and the right speed for it to go.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)