How do I make the player randomly teleport between doors?

Get help using Construct 2

Post » Mon Feb 02, 2015 9:49 am

I searched a lot but couldn't find anything too specific. You'd better check the image, should be easy enough to understand what I want to do:

Image

Objects: Player(0), Doors(1, 2, 3)

What I need is entering to the door 1, then getting out on, ideally, door 2 or 3, but any of the 3 will do for now.

My logic says that:
When the Player is overlapping Doors, press a button then set position Player to Doors UID's X and Y.

But I have no idea how to randomly take one of the 3 UID. I tried with a variable but it says "variable is not an object name".

Note: it's very important that the UID is randomly selected everytime I press the button, not on start of layout.
B
33
S
9
G
1
Posts: 156
Reputation: 3,034

Post » Mon Feb 02, 2015 11:17 am

You could store the UID of each door in an array then pick it randomly from there..
B
50
S
16
G
9
Posts: 1,098
Reputation: 11,237

Post » Mon Feb 02, 2015 11:43 am

notnsane there are many ways one can do this but, here is simple demo to start you
You do not have the required permissions to view the files attached to this post.
B
256
S
39
G
15
Posts: 1,983
Reputation: 41,034

Post » Mon Feb 02, 2015 12:28 pm

I kinda have a "NO ARRAYS PLEASE" philosophy so I try to avoid them like the plague, lol.

Thanks to both of you, testing the capx now =)

@Lordshiva1948 It's really similar to what I want, but as much as I try, I can't make it work with only one object. I replace tr with spawn and it always comes out in the same place. Then do it otherwise, I add the instanced variables to tr, and the same thing happens. It always comes out on the same "door".

Image

I want to avoid using two objects for this, else I would have to overlap them and then make one of them invisible. Could also create other issues, I think.
B
33
S
9
G
1
Posts: 156
Reputation: 3,034

Post » Mon Feb 02, 2015 2:01 pm

Easy enough, use the system choose parameter.

If player overlap door 1 then set variable randomDoor Choose (1 , 2, 3)
If randomDoor = 1 then spawn player at Door 1
if randomDoor = 2 then spawn player at Door 2
etc...

Sorry, I'm at work. If you need a Capx example then let me know. I'll do it late tonight or tomorrow morning (eastern time).
Kurieus
Come visit and play Blast Box!
B
15
S
3
Posts: 205
Reputation: 1,349

Post » Mon Feb 02, 2015 2:02 pm

To add on that, you could break it down by case of over lapping doors,
Eg.

If player overlap door 1 then set variable randomDoor Choose (2, 3)

If player overlap door 2 then set variable randomDoor Choose (1, 3)

If player overlap door 3 then set variable randomDoor Choose (1, 2)
Kurieus
Come visit and play Blast Box!
B
15
S
3
Posts: 205
Reputation: 1,349

Post » Mon Feb 02, 2015 3:12 pm

demo
You do not have the required permissions to view the files attached to this post.
B
256
S
39
G
15
Posts: 1,983
Reputation: 41,034

Post » Tue Feb 03, 2015 5:23 am

Thanks for the help guys, but this still doesn't work as intented.

Maybe I wasn't clear enough but I need to use only one object besides the player. There's no point on having duplicates of duplicates.

I tried using variables now but I don't know if to use instance variables or global variables. Or how to select a specific door (because the action should be triggered with Any door or I'll turn more crazy) Any help appreciated.

@mepis, can you elaborate your example? Also I don't mind having to choose like that, but my game will have like 10-15 doors, so it might be annoying to type, say "choose(1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)" for each door (deleting and adding one number, obviously)... but if there's no other way, then no probs =P

Made a new mockup to make this idea more "readable". The only objects here are "player" and "doors". Of course each door has a specific UID (created all of them with Ctrl+Click except the first one)

Image
Last edited by notnsane on Tue Feb 03, 2015 8:17 am, edited 1 time in total.
B
33
S
9
G
1
Posts: 156
Reputation: 3,034

Post » Tue Feb 03, 2015 7:12 am

Well, notnsane, I think I've got what you want. I even kept your colors. The player has platform, press down to go through a door.
What it actually does is teleport the player to a random door including the one he started at, but moves him again if he would appear at the original door. The UID of the origin door is stored as a separate instance variable in the player, and compared against the destination door.

What's handy about this over the Choose(1,2,3....) version is that you can dynamically add or remove doors to your heart's content*, and it won't change the algorithm at all. You can even just drop it down to two doors to verify that it'll never drop you back at the door you started at.

You may note that the doors and floors all have physics. Frankly, that was easier than aligning them all with the floor manually. You can remove them and it'll still work just fine.

Edit: Sod, left a bug in there. If you walked to a door after teleporting from it, you'd teleport again.

*Provided your heart's content doesn't include a single door. That will cause an infinite loop.
You do not have the required permissions to view the files attached to this post.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Tue Feb 03, 2015 7:56 am

This will avoid the entered door, slight mod to yours hope you don't mind
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Next

Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 23 guests