playMaker

Author Topic: Selecting tiles with mouse  (Read 1670 times)

Freeform

  • Playmaker Newbie
  • *
  • Posts: 4
Selecting tiles with mouse
« on: July 19, 2020, 05:11:33 AM »
Hi!
I've been fooling around with a simple 2D turn-based strategy concept, and quite quickly smashed against a wall. I want to make a movement system identical to 99% of turn-based games out there: you point your mouse at a tile, click it, and the character goes there.

I created a tile map and was able to make a movement system for my characters just fine, but problems emerge when I try to tie it to the tile grid and specific tiles. As is, I can't figure out how to even select specific tiles.

I tried using mouse enter and mouse hover global events to spawn an indicator over the tile being selected, but it will always spawn in the center of the tileset, acting as if it was a singular, whole object, and ignoring the grid. :-[

So far the only workaround that comes to mind would be to make each tile a prefab, but I'm afraid that doing so will damage the game's performance.

Is it possible to use playmaker and unity's grid tile system to reference specific tiles, or are there add-ons/plugins that would provide such functionality? How do I resolve this?

There have been some people asking similar questions, but those refer to moving across tiles using the keyboard, teleporting the player a single tile's length, but those solution don't apply to mouse controls. I need for the player to be able to select far away tiles easily.

nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: Selecting tiles with mouse
« Reply #1 on: July 19, 2020, 08:50:09 AM »
The "Mouse Pick" action should help with picking specific tiles.

Freeform

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Selecting tiles with mouse
« Reply #2 on: July 19, 2020, 10:41:22 AM »
I've been using the mouse pick action. However, if I try to pick an object or a game object, it appears to pick the entire tilemap as opposed to a singular tile. I can also pick a point instead, in which case the coordinates aren't limited to the tile, making the character move in a fashion unrelated to the gird.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7619
    • jinxtergames
Re: Selecting tiles with mouse
« Reply #3 on: July 19, 2020, 01:22:55 PM »
Hi.
if your grid size is set, that 1 tile is 1x1 you could 'round the point you picked.

So for example if you picked x2.343 y3.673 it should be converted to x2 y3 (or probably 2.5 and 3.5 to center)

Freeform

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Selecting tiles with mouse
« Reply #4 on: July 20, 2020, 01:49:59 PM »
If I understand your suggestion correctly, it is to:
1. Mouse Pick the position
2. Get Vector2 XY to put coordinates into variables
3. Round down the coordinates
4. Move the unit game object to the new coordinate

This could work, once I've got time to experiment again, I'll take a look.
In the middle of that I will have to compare starting and final position to figure out how much movement points it took, and if that action was legal, but it shouldn't be too difficult.


I do have one concern with this solution however. It is common in games of this nature to draw a path between current and selected position. For instance, if you right-click the tile you want to go to a flag will spawn on it, and dots on the tiles you will go through along the way. You click again, and the character follows that path.


Knowing just the coordinates towards the middle of the desired tile, is it possible to calculate the entire route the object will take, constrain it to walking within the tile grid, and to spawn visual aids along that path?


The importance of having such visuals is that with them I can make a dot red if the player is going to walk through another unit on their way, warning them about potential combat, or I could make the flag grey if the player is trying to move farther than they can.

nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: Selecting tiles with mouse
« Reply #5 on: July 20, 2020, 01:56:10 PM »
Use "Mouse Pick" action, then either:
1 - Split the point returned into separate floats and round them to the nearest whole number.
2 - Get the ecosystem browser for Playmaker and download the 'vector3 round to nearest' action (or whatever it's called).

As for a visualized path, I'd stick to a "go to" dot for now. You know, a dot once you've decided where the unit is supposed to go.

But I think the 'pathing actions pack' might have an action that returns a bunch of values for the actual path the agent takes.

Freeform

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Selecting tiles with mouse
« Reply #6 on: July 20, 2020, 03:10:36 PM »
Thanks for the advice, I will look into it. As you can tell my biggest weakness right now is not knowing much about the many, many actions available in playmaker. While these things will come with time, your advice is definiately speeding the process along.