Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tracking how much of a game object is within another game object

Discussion in 'Scripting' started by matias-e, Mar 2, 2015.

  1. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Hey, I'm kind of stuck trying to implement a piece of code that tracks how much of another game object is within another. As in, game object A moves/rotates and the code counts whether it is 0% to 100% in the other object.

    Any ideas on how this could be implemented with C#?

    Thanks.
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I think you should certainly use bounds on the main object. I would have the "inside" object carry a number of transforms strategically placed inside of it... So... Let's say you have a cube as the main large object. Then you have another cube as the one that may be in or out of the larger.

    On the smaller, I would place a transform at each corner. On these transforms I would have a script, or a manager that watches each, to see if any one is in the cubes bounds. You can then get a clearer picture of the percentage of the object is in the others bounds,
     
  4. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Thank you for the answers!