How do you get an actor to go into Region 1 and come out of another region?

Majora64

  • Posts: 536
Working on an asteroid-esque game and was wondering how to get my actor (a ship) to go into 1 region, and come out of another region at the exact entry point of region 1? Kind of like pacman and the tunnels. The behavior I have works but the ship doesn't come out of the x,y entry point of Region 1. I know it's possible and I read through the forums but couldn't find a clear method. I know there's a math equation I can apply but I'm not strong with math. Anyway, I attached my code. Thanks in advance!

letmethink

  • *
  • Posts: 2545
Use 'set x to ([x of region 2] - ([x of region 1] - [x of object])) for object' and do the same for y. Hopefully, I'm thinking straight and that is the correct equation. If not, post again and I will correct it.
~Letmethink

Majora64

  • Posts: 536
Nice! It seems to work for the location issue I was having but in-between the transition to Region 1 and Region 2 the screen flickers cause the actor thinks it's going to Region 1 and Region 2 at the same time. Here's the updated code. I'm thinking there's an offset I can use but I don't want the ship to teleport directly to Region 2; rather, I'd like it to smoothly glide from Region 2.

AV 2525

  • Posts: 4
Can anyone explain how this solution works? I keep going over it in my head, but just can't reason how this equation creates the intended behavior. I'd like to understand, just for my own personal development.

letmethink

  • *
  • Posts: 2545
Can anyone explain how this solution works? I keep going over it in my head, but just can't reason how this equation creates the intended behavior. I'd like to understand, just for my own personal development.
x of region 1 - x of object gets the distance in x between the player and region one. If you then subtract this distance you have from x of region 2 then you have the player at the x distance from region 2 that is was from region 1.

mmmagicmmmike. I will look at your problem later when I am at a computer, but a possible solution would be to use a 'slide to' rather than 'set x to'.
~Letmethink

AV 2525

  • Posts: 4
I get it now. So it's more like R2 - (R1 - Actor) instead of R2 - R1 - Actor.  Interesting. Thanks.

Majora64

  • Posts: 536
[Slide to] makes some sense I'll try it when I get home but I'll let you know.

Majora64

  • Posts: 536
Tried plugging the x and y equation (from the set x and set y events) you gave me and it doesn't work. I just used Normal in over 1 second if that helps.

letmethink

  • *
  • Posts: 2545
What does it do (in terms of 'not working').
~Letmethink

Majora64

  • Posts: 536
My ship will go up to region 1, and then the camera will switch to the bottom where region 2 is located and where the ship should come out. The ship eventually comes out but then starts to erratically move downward in an infinite loop skipping between region 1 and 2 which also results in a loss of controls. I'm using the follow mouse behavior just to test it in flash but the game will utilize dual joysticks on mobile but I don't think that affects it. Here's the code I'm using.

letmethink

  • *
  • Posts: 2545
Basically your code is currently skipping the player back and forth as the second part of the code will run as soon as your actor enters the second region. You have to add some validation against this. If you ask later,  I will explain this if i need to.
~Letmethink

Majora64

  • Posts: 536
What part of the code do I need to add the validation to? And is it best I try to work on the [slide by] method or the initial [set] one?

« Last Edit: July 07, 2015, 10:04:25 pm by mmmagicmmmike »