Make actor follow user selected path...

superfried

  • Posts: 24
Hello

Ok, so I am trying to develop a slightly unconventional control system for my main character. This will be for ios. So, imagine the floor is made up of square tile actors which are can be turned on or off by the users touch. Now, when the user selects a tile, after a pre-determined amount of time the player will move in the direction of the selected tile. Once the player reaches the tile in question, if a second tile has since been selected it will now move towards it. If not it will continue on it's original path until it reaches something solid or his doom. When the player makes contact the with a selected tile it becomes de-selected. (Please see visuals attached).

In principle this seems very straight forward, but in practise I think it could be quite complicated. I am not too hot with Stencyl yet, but I assume I need to create a boolean to declare whether a tile is selected. I presume I then set up a movement towards it and then clarify that when the x/y's are equal it should check for another selected tile.

However, how do I make sure he only travels at 90 degrees? Also, how do I make sure he moves towards each selected tiles in the order in which they were selected?

I am sure this is a little confusing so I have attached some visuals.

Any help will be gratefully received.


Superfried


Abigayl

  • Posts: 807
If you don't need 100% accuracy, you can use a tween (found in Actors palette). Use the "slide self" tween and change the code to the "to" format and then use the x/y of the tile as the location to move towards.

I mention the accuracy since tweens are known for being a bit finicky so if you need precision (for the player to be 100% on the spot, not a pixel off), then you will need a different idea.
If you need help, please check my tutorials either here or Kongregate (http://www.kongregate.com/accounts/Abigayl) or come over to my stream: http://www.livestream.com/poweredbyflowers

captaincomic

  • *
  • Posts: 6109
In 2.0 there will be a pre-shipped behavior "Follow Path" that should work well for your needs. ;)

Do you allow diagonal movement, or just up/down/left/right?
You would need to add nodes to the path when you select a tile (calculate the center of the tile you just clicked/touched and add it as a node). If you don't allow diagonal movement it would be a little bit more difficult, but still doable.

You can check out the nightly build for the behavior.

superfried

  • Posts: 24
Hi


Thanks for both of your replies.
I will take a look at the slide/tween options.

With regards to v2 a couple of question...

So, first question, when is v2 likely to be released?
Secondly, if I download the nightly build, will it replace the current version of Stencyl I am using or be usable in addition to the current version?
Lastly, with the follow path behaviour, does this have to be a pre-set path or can it vary depending on the user in put?


Thanks in advance.


Superfried

Abigayl

  • Posts: 807
SW2 is scheduled to come "soon", but from what I know, that "soon" is still a little ways away.

The nightly build is indeed SW2 and will not replace your current version. In fact, you will likely want to keep your current version just in case there is an unforeseen issue with the nightly build.

With your system of clicking a tile, you should be able to allow the actor to follow the user-defined path. Just make sure the actor reaches the first tile before moving to the next (if going to strict 90-degree movement).
If you need help, please check my tutorials either here or Kongregate (http://www.kongregate.com/accounts/Abigayl) or come over to my stream: http://www.livestream.com/poweredbyflowers

captaincomic

  • *
  • Posts: 6109
I think 2.0 will be released soon. (March?)
If you download the beta/nightly install it separately and do a backup of your games first.
(Like it says here: http://community.stencyl.com/index.php/topic,6869.0.html)
And yes, the path can be set interactivly.
(Ninja'd.)

superfried

  • Posts: 24
Wow, thanks for the prompt reply, I assume you are on a different time zone.

I will check it out and let you know.

As you were...



Superfried


Hectate

  • *
  • Posts: 4643
A small design consideration that you will need to address eventually:

If the selected tile is diagonal - is that allowed? And if so, should the character move up or down first or left or right first instead? You will need an answer to this to complete the behavior.

If you look at some games, you may notice that many of them vary this based on the distance on each axis. For instance, if you have to move 5 down and 2 right, the down motion happens first because there are more steps. Other games mix it up; down down right down down right down, for example.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

superfried

  • Posts: 24
Hi Hectate


Yes, I was thinking about that. Diagonal movement will not be allowed. With regards to different ways to get from A-B, I was thinking that one way to solve this is to insist the player selects every tile on the chosen path. Therefore he will always have a tile perpendicular to his location to move towards at any given time. This will also make it more tricky for the player especially as things speed up, but for longer, straight runs they would be able to use a swipe movement across multiple tiles rather than individually selecting each.

I have been trying to find game examples on the forge, but nothing so far. I found an interesting AStar pathfinding example, but when I opened it something was broken and it would not test. I also stumbled upon the pathfinding example by Greg, but this looked very complex and I was not sure I would be able to tweak this to my requirements.

Thanks for your help.


Superfried

superfried

  • Posts: 24
Ok, I am officially confused.

On the floor tile actors I have a behaviour which switches the animation between selected and not selected when clicked/touched by the user. Also, if the player collides with it, the animation switches to fade animation and it is now selectable again.

Next I added a game attribute boolean called 'selected'. This states in the tile behaviour that when the animation for self is 'selected' the boolean 'selected' is also true and when the current animation or the tile is 'unselected' the 'selected' boolean is false.

Now I am trying to create a behaviour for the player that states when x of selected tile is greater than x of player it moves right. However, how do I declare the 'x' value of selected since it is only a boolean and an animation? Does this mean I will need to change it so that when the user clicks a tile it changes to a new 'selected' actor rather than an anim, so will therefore have an 'x' value?

This seems like a bad idea as increasing the actors will only make the game heavier, unless I include some kind of kill action.

I am sure I am probably looking at this the wrong way.

Thanks in advance.


Superfried