playMaker

Author Topic: How to determine how far a player can move  (Read 3595 times)

MtnMan365

  • Playmaker Newbie
  • *
  • Posts: 3
How to determine how far a player can move
« on: November 21, 2019, 07:47:30 AM »
I am building out a standard hex style board game. Certain player classes, i.e. hunter, ninja, etc. are only allowed to move a certain number of spaces per turn. In most cases the player can only move to another hex directly adjacent to the one they are on. Then they can select another one adjacent to the one they just selected BUT not the one they just came from until they run out of moves.

What action should I be using to check this?

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: How to determine how far a player can move
« Reply #1 on: November 21, 2019, 08:49:48 AM »
I think you can make something like:
variable for 'totalMove', 'currentMoveLeft', and just subtract by 1 every time the player moves until it reaches 0.

For checking adjacent tiles that you have been there before, you can use raycast to determine that area is prohibited to access again. (Send a raycast to the opposite direction of player movement and turn it off/make it inaccessible.)

There may be other ways to do it.  :)

Good luck,
Rechronicle

MtnMan365

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to determine how far a player can move
« Reply #2 on: November 22, 2019, 09:36:58 AM »
Thanks so much for the reply. I don't know how to explain what I am going for without a lot of visual help. So I thought a video would be best... if I am allowed to post one... we will see I guess.

Here is what I am going for...
https://www.loom.com/share/d978f4d6b4f64ea0a2ace4ed519f05c7

I will try and break it down in steps...

  • Player on hex
  • Player has two moves
  • Check 360º around the player to see what tiles they can move too
  • Click one of the eligible surrounding tiles to select one move
  • Then check the surrounding area of tiles that can be moved to that surround the first selection
  • Then there would be a done or move button to hit and the player would move there
  • The player turn would be over




Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to determine how far a player can move
« Reply #3 on: November 22, 2019, 10:54:45 AM »
When you want to do a given action repeated times, you can do it like rechronicle wrote above. Before undertaking the action (in this case: move to one adjacent tile)  check a variable (number of moves), and after the move reduce that variable by one. At some point, e.g. next turn, you need to fill it up again. You likely have a “new turn” global event which could be used to trigger the refill.

The complicated part comes from “previewing all moves”, i.e. when the player can move the whole distance at once and needs to see the options. Even though it looks superficially similar, it’s a different implementation.

I would probably test out something like this:

1) check if a simple “distance” check methods works, look for distance actions and rays.

2) if not, look into tile based pathfinding to determine possible moves.

3) if all fails, custom: starting tile can set eligible adjacent tiles into an accessible state. Activated are tiles that can be moved on, and which are not yet set to accessible. The accessible tiles learn each which tile has activated them, and reads a int variable (representing distance), and adds one to store in themselves. This value is checked against moves, and if it exceeds them, the tile does not activate the next tile. The tile the player is on is 0. The adjacent ones have a 1, the adjacent to the adjacent ones a 2 and so on. You can then also use the value to e.g. colour the tiles, of use the value for gameplay.



rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: How to determine how far a player can move
« Reply #4 on: November 22, 2019, 11:21:13 AM »
See the attachment, maybe it might work on your player movement with cell grid. Using array and collider as a sensor to check nearby accessible cells.

You can check Tile-Based pathfinding too, as mentioned by Thore.

(Just got this little idea, and I ended up visualize it.)

I hope it helps.
Rechronicle

MtnMan365

  • Playmaker Newbie
  • *
  • Posts: 3
Re: How to determine how far a player can move
« Reply #5 on: November 23, 2019, 02:55:35 AM »
This is awesome. I was trying earlier to do something where I had a detector with a collider and I was going to trigger a boolean when they were overlapping other detectors after the first click of a hex. However, I could not figure out how to get it work on an invisible object with a collider. I like the idea of working with arrays... I am a super noob and have not done that yet... and I think that will actually be better. I am watching all sorts of videos now and already seeing the possibilities.

Thanks to each of you for the advice and continued help. I am always hesitant to ask because I am so new but you guys have been really great so far. Super appreciated. I am slow and have a few things to learn with this so I will try and check back in and let you know where I landed.

Thanks rechronicle and Thore! Just wanted to let you both know that I read your comments, appreciate them, and am trying to implement them.

FYI, the visualization was awesome!

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: How to determine how far a player can move
« Reply #6 on: November 24, 2019, 01:46:14 AM »
Great to hear that.
Yes! Please share if you found/develop a nice and easy way for tile movement.


Good luck on the development, anddd never afraid to ask around. :)

UPDATE: Just found this yesterday and I think this script is super useful for grid-movement. Check it out!


See ya.
Rechronicle
« Last Edit: December 02, 2019, 04:56:56 AM by rechronicle »