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. Dismiss Notice

Obstacle avoidance in the canvas

Discussion in '2D' started by Markedavis2001, Sep 28, 2017.

  1. Markedavis2001

    Markedavis2001

    Joined:
    Nov 20, 2013
    Posts:
    30
    Hey Unity folks,

    I'm making a little arcade style game in Unity and it's all totally in the canvas. I'd like to have some sprites moving around from one place to another, but I'd rather not script them manually so I'd like them to avoid obstacles on their own.

    Does anyone know of a way to get something in the canvas to behave similarly to how they would in the game world?
     
  2. Deleted User

    Deleted User

    Guest

    Are you asking if you can use the physics system on a canvas? Are you asking if you can get sprites to move around without scripting them? I'm not sure I understand the question.
     
  3. Markedavis2001

    Markedavis2001

    Joined:
    Nov 20, 2013
    Posts:
    30
    I guess I'm asking if there's a way to get the physics system to work on the canvas, or something similar anyway. I've made games with agents that use Unity's pathfinding in the gameworld, but in this new project everything is in the canvas. I'd like to have the agents move from A to B, avoiding panels that I've marked as static obstacles.

    Does that make more sense?
     
  4. Deleted User

    Deleted User

    Guest

    Physics objects will behave normally on a canvas, just add 2D colliders and rigidbodys as needed. As far as I know unity doesn't have any built in 2D pathfinding, you'll have to make it yourself or use a 3rd party asset.
     
  5. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    Is the nav mesh agent working in 2D?
    I guess you will need a way to resize your UI components and your colliders attached to them in script, else, you will have trouble if your UI get scaled to match user's resolution.
     
  6. Markedavis2001

    Markedavis2001

    Joined:
    Nov 20, 2013
    Posts:
    30
    Looks like I can't generate a navmesh that is vertical. Anything over 58 or so rotation and the navmesh doesn't render.

    Ah well - maybe obstacle avoidance is too much to expect for something living in the canvas.