Search Unity

Calculating distance between meshes

Discussion in 'Physics' started by hsnk, Feb 13, 2019.

  1. hsnk

    hsnk

    Joined:
    Jul 24, 2015
    Posts:
    8
    Hi
    I'm building a game similar to the "Operation" board game (here's a fun intro in case you don't know it)

    In my game, players draw a path through an obstacle course and launch a projectile. The projectile follows the drawn path and if there is no collision, scores points. If the projectile comes close to the obstacle walls, the players loses points depending on how close the projectile is to the wall.

    Now, the problem I'm facing is that both the projectile and the wall are both irregular shapes. I can easily detect the collision but for the life of me, I can't figure out how to calculate the distance between the projectile and the wall when it's just close by.

    I *could* calculate all the vertices on the projectile and shoot raycasts to hit the walls and calculate the smallest distance to the wall but this brute-force method feels inefficient.

    Any suggestions?!
     
    a4salih4a likes this.
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536