playMaker

Author Topic: Implementing Movement Between Points on an Array [SOLVED]  (Read 6236 times)

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Implementing Movement Between Points on an Array
« Reply #15 on: January 14, 2016, 12:11:48 AM »
It worked! To a point.

I've dynamically pulled the Tile Array by getting my tile objects. They came in backwards starting with Tile7, so I used another state to shuffle them around using an Array Reverse. Next I've set up the global variable of Current Tile by associating it with element 2 (Tile3) in the array. I then tell the player character to move it's position on start to Current Tile and then update that variable.

That all works!

Where I'm stuck now is getting the player to move between tiles. I want to lerp the player between the vertex variable of CurrentTile, a the vertex variable of NextTile, but I can't seem to find a way to relate the two with one another via the array. I'm trying to use Array Get Next, but it spits out an Int, and doesn't seem to want to accept anything else. Once again I feel like I'm missing something basic.

I know what I have to make happen, somehow translating that int into a vector2 position, I just don't know the tool to use to make it happen.

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Implementing Movement Between Points on an Array
« Reply #16 on: January 15, 2016, 12:00:06 AM »
Just got home from the gym and am starting to work at the conversion problem. I've created a loop event in my game controller to run through the contents of the array. I'm really stabbing blindly here, but based on your tutorial video MDotStrange I might be able to create a variable off of the listed contents rather than just selecting a specific tile, as I did with Current Tile.

I need an int (which slot in the array)
I need a game object (which tile)
And I need a vector (the tile's location)

I feel like the solution is no more than three feet away...

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Implementing Movement Between Points on an Array
« Reply #17 on: January 16, 2016, 12:15:45 AM »
IT'S WORKING! Partially.

I started walking the problem backwards, reasoning out what variables I was going to need to move the character to another space. When I got to the point where I was looking at what the move action would be I realized that iTween's Move To action would accept a GameObject. That meant that one of the three variables I thought I would need, a Vector, wasn't actually needed.

I started by building the Game Controller FSM. I collect the Tile Game Objects to set up the TileArray, associate a slot on the Array (#2, which holds Tile 3) with a Game Object (CurrentTileObject), then associate that Game Object with an Int variable (CurrentTileInt), and finally establish NextTileInt as just being 1. I then used iTween to snap the player to the variable CurrentTileObject. He popped right over to it. So far so good.

I then spent the next three hours building and rebuilding the actual Player movement script. On a key press the script does an Array Get Next and starts with CurrentTileInt and ends on NextTileInt. It finishes by associating NextTileInt with NextTileObject. The next state adds the CurrentTileInt to NextTileInt, sets CurrentTileInt to itself immidiatly after, then do an Array Get to associate CurrentTileInt with CurrentTileObject. The last state is another iTween, which now moves the player from wherever they are to the new position of CurrentTileObject.

I had the FSM done about two hours ago, but when the player moved, he would get to the correct tile, and then snap back to his original position. I reworked the whole thing a dozen times or more, trying a bunch of configurations, and getting the same result every time. I was pulling my hair out until a friend who had given me some early help asked if the script he gave me to run the player early on was still active. Sure enough, it was, and once I unchecked that the player moved and stayed in place.

Of course the next thing to do was to reverse the process. I figured I could use a -1 for the NextTileInt to move back as space on the Array. Wrong. I get locked in the first Array Get Next state.

I'm not entirely sure how I'm going to fix it, but this is a huge step forward!

Thanks again Mdotstrange!

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Implementing Movement Between Points on an Array
« Reply #18 on: January 16, 2016, 01:22:16 AM »
Sounds about right  :)

No problem- if you have any other tutorial requests let me know- always looking to add new learning stuff to the Playmaker scene.
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Implementing Movement Between Points on an Array
« Reply #19 on: January 16, 2016, 01:34:24 AM »
YEAH!!! Movement is working!

I was able to dump an entire state, I didnt need to do an Array Get Next, or the NextTileInt. I was able to flush a bunch of variables as a result.

I ran into the problem of my math increasing with each key press at the last tile in the array, so even though the player couldnt move past it, if you wailed on the button while at the wall you would have to press it an equal number of times to get moving in the opposite direction.

Next step was a check, so a Bool saying you are or arent at the wall. another state to circumvent the whole movement system if it was true, and an action on the opposite movement direction to deactivate the AtWall Bool. I started by using the Array Get's Out of Range Event to fire off the Bool activation, but that proved problematic because it wouldnt activate until the player tried to move beyond the Array. So you would have to get to the wall and then try to move out of bounds before it activated. This let the counter get one number higher than it was supposed to, meaning one extra button press to start moving back the other way.

The solution here was to learn about Int Checks, and then use that, set to the last tile, to fire off the Bool instead of using Out Of Range. Dirt simple.

I'm incredibly excited, overly proud of myself, and super exhausted at the same time, I want to leap right into camera stuff, but a cursory glance suggests I'll be learning about sending info between FSMs, and while that might be easy it's well beyond my energy levels at this point.

This problem is officially SOLVED at this point.