Search Unity

Good method for line of sight check on large object? (Computer AI)

Discussion in 'General Discussion' started by Xhitman, May 23, 2019.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    268
    For example, a human(computer) use rocket launcher to attack a battleship (player) in 3D.

    I have the following problems:

    1. I cannot use battleship.transform.position for LOS checking, because it does not make sense for the the human attacking the same point again and again.

    2. The closest point of the battleship collide for LOS checking seem to be fine, but if it fail, how to find other points for LOS checking?
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    11,786
    How often do you need to do this?

    The simple option would be to have a number of nodes on the ship, and check line-of-sight against each of them. However, this will fail if you can see a small part of the ship through a gap or hole, and none of those nodes happen to be in the area you can see. So you'd balance between how many nodes you have, and keeping the checks reasonably cheap.
     
  3. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    4,407
    EDIT: angrypenguin beat me to it!
     
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,114
    Use bounding box to approximate the shape, check against the box that get the hit, possibly recurse a tree of primitive depending on precision needed.
     
    ShilohGames likes this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,618
    Depends what complexity of model is, you can fire raycast to shape of battleship, to get hit position on the shape. You may want simplified collision mesh for that reason.

    Then based on offset calculations from center, do whatever you need.

    Or as mentioned, use approx bounds, for simplified collision / hit detection.
     
  6. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    268
    Which method is the best performance for a RTS game? Something like 30 computer units attack a large player battleship(1 attack per 2 sec)
     
  7. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    4,407
    Depends on loads of factors that are specific to your game. Best way is to test each option and evaluate the quality and consistency of the result vs the performance hit.
     
    Ryiah, angrypenguin and Antypodish like this.
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    4,618
    As mentioned, test different methods.
    But if you want learn about complex 3D damage mechanics for RTS, for small and large units, look into https://zero-k.info/
    Try find on their forum answers, if can not find ask there.
    Or grab their code, and study it.