Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question 2D Isometric - How do I make a game object snap to a grid?

Discussion in '2D' started by JD419, Dec 24, 2021.

  1. JD419

    JD419

    Joined:
    Dec 6, 2021
    Posts:
    2
    Currently making a 2D Isometric tactics like game, I made a selector icon that will be used to select the tile which to send the character to (this will appear after you select the character) , and I managed to get the selector to follow the mouse, but I need help with getting the selector to only move/render when on a walkable tile and snap to the those tiles when I move the mouse around. Anyone know how I would do this?

    Additionally I will need the character to snap the grid when they move, but I imagine that will be a little simpler since the character will go to wherever the selector can go. Thanks!
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    always round the coordinates of the cursor, then set the transform of the selector to those rounded coords

    this works best if your world coodinates are 1:1 to the grid

    if its not 1:1 if its 2:1 for example then round to every even number etc
     
  3. JD419

    JD419

    Joined:
    Dec 6, 2021
    Posts:
    2
    I see so basically instead of trying to convert everything else to the coords of the grid, I just convert the mouse cursor coords for purposes of selecting the grid and things on it. This helps a lot, thanks!