Search Unity

Movement-OK Checking Using Raycasting: Really the Best Way?

Discussion in '2D' started by KrisSchnee, Feb 18, 2015.

  1. KrisSchnee

    KrisSchnee

    Joined:
    Mar 9, 2014
    Posts:
    15
    Hello. I'm (re)learning Unity after abandoning a promising project last year, and just did the "scavenger" 2D tutorial. I'm puzzled by the way movement is checked: a 2D raycast toward the target space. Seems to me that that's okay for making a one-tile movement, but only if you're confident that no other character will also try to move into that space, and only if you're just thinking about one tile's movement at a time.

    The way I did things in my abandoned project, I had a board object keep track of which tiles were occupied, marking a space as occupied as soon as a character decided to move there. However, I also had no idea what a coroutine was, so characters instantly moved to their target spaces. My game was real-time (but tile-based), too, so the effect looked especially clunky.

    Do you think it's a sensible plan for me to imitate the movement coroutine system in the scavenger tutorial, while using a central "is this space occupied" array/list like I've been doing, rather than the tutorial's 2D raycasting? Maybe I should abandon the notion of the characters being stored "in" particular tiles and let them move freely, impeded only by 2DBoxColliders, but the gameplay revolves around changing tiles that you're standing on.

    (Side note: Seems like maybe I'm just uncomfortable with "the Unity way" of finding information about the state of the game world by querying the space that characters are being drawn in, rather than a separate data structure (as in the Model/View/Controller pattern).)