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

Projecting movement space

Discussion in '2D' started by OliverTheLove, Mar 13, 2017.

  1. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    22
    Hey!

    I'm trying to create polygon colliders on my platforms, which will act as triggers/boundaries where my character can move. This is to ensure playability for when I automatically generate levels, tossing away levels which don't connect from start to end.

    However, I need to be able to modify the collider if another platform intersects the area.
    I've tried to illustrate it with my S***ty pictures. In the first image, the black box shows the platform, and the purple shows the area where the player can move from the platform.

    In the second image, a new platform is placed under. The blue area shows where the player can move from the new platform. The orange shows the area which is no longer accessible from the first platform. Green shows no longer from first, but accesible from second.

    Is there a way how I can change the polygon collider to end at the new platform, or is there another technique which I should look into instead, e.g. raycasting or some form of nav mesh?
    shittyDescription2.png
    shittyDescription.png
     
  2. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    22
    Hey!

    I ended up solving the issue by giving each platform a bunch of rays which I used as projection area.
    By using a Depth First Search algorithm, I used every platform as a unique node. At each node, I checked if my rays were hitting the current node I was looking into. If it was, I checked that nodes neighbours, until I finally found the end platform.

    This is what my start platform (green) looks like when I draw all the rays on it.
    Madam Legume projection.png

    And this is how my DFS-algorithm found the end platform by raycasting from different platforms until the end :)
    Madam Legume projection2.png