playMaker

Author Topic: [SOLVED] Restrict Player Movement  (Read 1619 times)

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
[SOLVED] Restrict Player Movement
« on: June 06, 2020, 12:06:09 PM »
I have 9 squares setup each square is a button.

Once a button is clicked it gets its own position and stores that in a global variable (buttonPos), then it sends a global event to the player (GetLocation).
Once the GetLocation event is called on the player, the players state does a Rect Transform Set Local Position (which is the bottonPos global variable) to move the player to that location (position 2d).

I would like to restrict player movement and am stumped on how to implement this. As seen in the attachment below. I would like to make it so that if the player is in the center of the squares I would only want it to move up, down, left and right. But if the player is in the top left corner I would only want the player to move right and down as shown in the attached image.

How should I approach this? If I have to change the way everything is done above that's perfectly fine and I appreciate any thoughts or suggestions.
« Last Edit: June 07, 2020, 10:07:16 AM by Kodagames »
Have I said how much I love playmaker!!! This is one amazing tool

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: Restrict Player Movement
« Reply #1 on: June 06, 2020, 04:44:10 PM »
I think what I'll try to do is turn off the other buttons interactable check box depending on the players position which bring me to another question:

How would I compare the players 2d position against the other 8 positions?

EDIT: On the ecosystem I found Vector2 Compare (surprised this isn't a standard action :))
« Last Edit: June 06, 2020, 05:04:18 PM by Kodagames »
Have I said how much I love playmaker!!! This is one amazing tool

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Restrict Player Movement
« Reply #2 on: June 06, 2020, 04:58:28 PM »
Hi.
depending on how movement is done maybe you could use arrays as a grid

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: Restrict Player Movement
« Reply #3 on: June 06, 2020, 05:10:31 PM »
@djaydino
Movement is done by setting the players 2d position (onClick). I wouldn't mind learning how to use arrays as a grid :)

I think I'll change everything to 2d instead of buttons so that I can use colliders instead and hopefully learn how to use arrays in-between creating this game ;)
« Last Edit: June 06, 2020, 07:22:41 PM by Kodagames »
Have I said how much I love playmaker!!! This is one amazing tool

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Restrict Player Movement
« Reply #4 on: June 07, 2020, 04:27:33 AM »
Hi.
1 array would represent 1 line so in your case you would have 3 arrays with 3 elements.

It is best to use 'Array Maker' with this as the uses reference.
so you can name the arrays '0' '1' '2' (arrays start wit 0)

So array 0 element 0 would be Top left and array 2 element 2 would be bottom right. (arrays are the vertical lines)

Now you can do a check that if you are on 0,0 and player presses a direction that if target direction is less than 0, it can not go that way (for both directions)

if player would be on array 1 and element 2 (bottom center), player can go to array 0 and array 1 (left and right)
But can only go to element 1 (up)

(you can do for example a int operator 1 + 1 then check if greater that 2 and 1-1 and check if less than 0)

I used this system on my Tetris game i made :
http://www.jinxtergames.com/web-games/tetris/

Array make also has a 'Array List Table' Component which works as a grid, but i have not tested that one my self yet.

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: Restrict Player Movement
« Reply #5 on: June 07, 2020, 10:06:46 AM »
@djaydino,

THANK YOU! THANK YOU! THANK YOU!
Your explanation is clear and concise, its greatly appreciated!

I changed the way I was handling this and created a collider for each spot, if the spot gets clicked on the player will move to that spot, I also track the players movement (get position), if the player is in the center the corner spots are deactivated, but now that see how you would use the array I'm definitely going to implement this, I can't wait to try it!

P.S.
I was struck on your site playing Tetris for a while lol Again Thank you djaydino!

EDIT: Works awesomely (snippet image attached).
« Last Edit: June 07, 2020, 10:39:43 AM by Kodagames »
Have I said how much I love playmaker!!! This is one amazing tool

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: [SOLVED] Restrict Player Movement
« Reply #6 on: June 07, 2020, 01:12:19 PM »
Hi.
No problem, Happy to help :D

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: [SOLVED] Restrict Player Movement
« Reply #7 on: June 20, 2020, 04:26:51 PM »
Ok, Im still looking into arrays as grids but finally solved the initial concept and I just had a few things out of wack. So here's how it was done:

Input State:
Get Key Down, Key = Left Arrow, Send event = Move Left
Then the same Action for Right, Up and Down

Move Left goes to the next state Check L:
In this state Im now getting the position instead of in the input state.
Get Position, Game Object = Use Owner, X = newX (var)
Float Compare, Float 1 = newX, Float 2 = -1, Tolerance 0,
Equal = Return (event name), Less Than = Return, Greater Than = Move Left
*return event goes back to the input state, Move Left goes to the Move L state

Move L (state):
Do tween Transform Blendable Local Move By, Game Object = Use Owner, By = x -1.8, Finished Event = Wait For Input (which goes back to the Input state).

And that's it in a nutshell I do one of these for each direction.

* Notice Im doing a float compare for -1 instead of -1.8 (which is what the player movement in increments are in the Do Tween), when I was using -1.8 most of the time the player wouldn't be able to go any further left but once in a while it would, this was the whole issue which drove me nuts lol Changing this to -1 instead makes it work fantastic now no matter where the player is on the board it will never go below -1.8 to the Left and the same for right, up and down.

Hope this helps someone else in the future trying to set bounds using incremental movement. Woohooo!
Have I said how much I love playmaker!!! This is one amazing tool