Search Unity

Distance from an object to a all raycast or all box collider

Discussion in 'Navigation' started by AlexandreH5, Aug 24, 2019.

  1. AlexandreH5

    AlexandreH5

    Joined:
    Sep 24, 2013
    Posts:
    61
    Hello,

    In a top down twin stick shooter. I would like to do an auto aim for improve the game feeling with the stick.

    So I drew visually thanks to a mesh renderer a line that is child of the player and indicates the forward direction (facing him).

    Now, either using a raycast or a collider (browsing the whole line) I'd like to be able to say.
    If the enemy is near the raycast or the collider then I hang the target on the enemy.

    I tried with a magnitude but it takes the base of the line whatever happens. I'm giving you an example below.

    Thank in advance.

    Alexandre
     

    Attached Files:

  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    This is unrelated to navigation, you're posting in the wrong subforum.
    However, this link should answer your question.