playMaker

Author Topic: Checking if two objects are in the same space? [SOLVED]  (Read 546 times)

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 35
Checking if two objects are in the same space? [SOLVED]
« on: April 08, 2022, 01:56:52 AM »
I'm creating a simple level generator, where different level chunks (currently just square tiles with box colliders for hit detection) are loaded onto grid positions with connecting doorways. The only part not working is the state where it finds if the tile is occupying the same space as another tile. Here are the different methods I've tried so far and their results.

Raycasting from a position just above of the new tile, casting downward. Could not detect any objects.

Get Overlap from the position of the new tile - returned no objects

Using a trigger stay event (and checking the 'is Trigger' box on the colliders) Returned nothing

Find Closest - This one sometimes returns the correct object and sometimes returns an object a few squares away

I'm sure I'm missing something in any or all of these methods but I can't figure out what. Or perhaps there's an easier method for I'm trying to achieve?

« Last Edit: April 16, 2022, 08:40:50 PM by RobotGoggles »
When life hands you insomnia, make video games.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Checking if two objects are in the same space?
« Reply #1 on: April 12, 2022, 10:26:45 AM »
Hi.
if its grid based, maybe make an array or some array where you store the positions of what have been placed.
Then you can loop thru the list and do for example a distance compare

or for example if you grid is for example 5x10, have 5 arrays (int) and sized 10

Then if you place something in the top left then set a int in the 1st array on index 0
The int can be any value which can help to know what is placed.

if 0 the spot is empty.

Probably best to use array makers array lists (you can set a reference on the array : 0,1,2,3,4 for the rows)

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 35
Re: Checking if two objects are in the same space?
« Reply #2 on: April 16, 2022, 08:40:04 PM »
Thanks - I was able to achieve something similar using a regular Vector2 array and saving/checking the locations that way the locations. Works like a charm now
When life hands you insomnia, make video games.