Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Best way to make a character move in a 2D point & click game.

Discussion in 'Scripting' started by StephenW, Sep 30, 2018.

  1. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    28
    Hi Everyone,

    I'm looking to make a 2D point and click adventure game, and I'm having a bit of trouble figuring out the best way to do the movement system.

    I want to have it work like in Monkey Island, where the character can go left and right, as well as up and down so they can walk around objects or maybe to a path at the top of the screen.
    An example would be this part of the game
    the character can go left and right, then the exit is up at the top.

    I don't know how this is set up, is it purely 2D and he is just walking in the Y direction? Or is the movement 3D on a 2D background?

    Also how would I go about constraining movement when walking into terrain and characters?

    I have my left and right movement working, all it does is move to where the mouse was when it was clicked, but it can't do anything else.

    Does anybody have any advice or know of any good tutorials to follow for this?

    Thanks in advance
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    You have to scale the character as he walks higher on the screen. It's kind of based on the perspective of the screen shot so it's probably slightly different for each scene. It's not 3d, it's a 2d sprite on a 2d backdrop. You change the drawing order when he goes behind something. The things he goes behind have to be separate sprites. You kind of go by the angle for which walk motion to use, going straight back, or going sideways.
     
  3. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    28
    Thanks for your reply.
    Yes I figured I'd have to change the character size, I didn't think about changing the drawing order though, so thanks for the idea.
    The bit that really has me stumped is how to get him to follow the mouse cursor while following a path, so he doesn't walk over buildings or places where he shouldn't.
    I tried using collisions, but I couldn't get it to work, since the setup i using, the player is a kinematic rigidbody and doesn't get blocked by colliders.
    I have him following the mouse, but straight through a collider
    Colliders might be the complete wrong set-up for this type of game, I don't know.
     
  4. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    160
    I would think NavMesh would be best. Bake a nav mesh. Get the location of the mouse click and then have the nav agent go to the position. You will need to look up how to do those things but it is pretty easy.

    Go here: https://docs.unity3d.com/Manual/nav-Overview.html

    Take a look at building a NavMesh and then creating a NavMesh Agent. You will probably also want to look at Creating a NavMesh Obstacle.
     
  5. StephenW

    StephenW

    Joined:
    Mar 29, 2016
    Posts:
    28
    Thanks, I'll look into the NavMesh. Does it work in 2D?
     
  6. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    160
unityunity