Overlap of collision's boxes

Dax85

  • *
  • Posts: 97
Hi all!
I'm having an hard time with a "simple" thing in my game.
I have a grid made of actors named "cells" that makes the map of my tactic chess game. When mouse is over a cell, this one lights up. Next pic show how i have a problem when 2 or more collision boxes overlaps, lighting 2 or more cells at same time, becaus of their different heights.



I'm trying to make the game so that when mouse is on 2 boxes it will light only the tallest cell.
I tried many ways, but everyone has some flaws..

The "lighting" of cell happens as a simple boolean switched on when mouse is colliding with cell and switched false at end of "always" bracket.

rob1221

  • *
  • Posts: 9473
First you'll have to check the highest level/height of the cells the mouse is over.  Assuming your actors have some identifier for their level/height, that's as simple as looping through all cells on the screen and checking for the highest level/height.  The second step is much harder, and that involves checking if the mouse is within the visible top part of the cells.  You'll most likely have to use matrix math for that.

EDIT: Thinking about it some more, these steps are probably in reverse order.  The height check would probably be second.

Dax85

  • *
  • Posts: 97
Thank you Rob. =) Yes, i was following that logic but always had some problems.
Now seems i resolved setting a global variable to check which heights are involved and lights only the one with higher value. The messy part was resetting those values after exiting a cell and before entering a new one, but i made a trick with a one-time switch ;P

In facts was much easier than i thought, sadly when you overthink about a problem you start to avoid simple solutions xD