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

Get help using Construct 2

Post » Sat May 07, 2016 12:11 am

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:

Image

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).

Image

Right now what happens when the player blinks is this:

Image

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

Image

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?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Sat May 07, 2016 12:27 am

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 ;)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 209
Reputation: 3,476

Post » Sat May 07, 2016 2:54 am

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.
B
18
S
9
Posts: 103
Reputation: 1,817


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests