Get data from overlapping sprites or areas

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RakuNana

Hello everyone, I hope everyone is well! Anyway I’ve been stuck on this problem for almost 3 weeks now, and, still can’t find a concrete solution. What I’m attempting to do
is, for player units and enemy units to have sprites/areas with a shape(similar to tetris blocks) These shapes are the range of the enemy units and player units. If a player unit shape and enemy unit shape overlap each other then either the player unit or the enemy unit can be attacked by the other. What I’d like to happen is when the player unit and enemy unit have an overlapping shape I want the data(atk,def,mag,etc) of the opponent to be stored into a list/array. That way only the name of the units that are in range can be attacked!

I’ve tried get_overlapping_areas as well as Rect2().intersect(“parameters”). And neither of them seem to work for what I’m attempting to do. Overlapping areas only works for one on one collisions, as if I add more then one overlapping area, it will ignore some of them, and Rect2().intersect(), I can’t find a way to get the data from the overlaps. It only returns true or false. Essentially if the sprites or areas are overlapping, The player can get the data from all the enemy units and vice-versa.

here’s a mock-up:
Note images are small, sorry about that face palm
Player and Enemy overlapping shape:

Player Button pressed to get data:

Enemy Button pressed to get data:

some snippets of code for intersecting sprites:

func intersecting_elements():

for x in SI_areas.get_overlapping_areas():
	
	var Shape_sprite_coll = Shape_rect.intersects(SI_areas.get_parent().get_parent().Shape_rect)
	
	if Shape_sprite_coll:

        if not get_parent().attack_in_range.has(SI_areas.get_name):
		      x.get_name = get_parent().get_data
		      get_parent().Attack_in_range.append(x.get_name)
		      

code for overlapping areas:

func find_demon():

for x in SI_areas.get_overlapping_areas():
	
	x.get_name = get_parent().get_data
		
	if not get_parent().attack_in_range.has(SI_areas.get_name):
		      x.get_name = get_parent().get_data
		      get_parent().Attack_in_range.append(x.get_name)

Thank you in advance!

The image links you posted aren’t working. You need to change the links’ access (on Google Drive) from Restricted to Anyone with the link.

jgodfrey | 2023-06-15 01:57

Sorry about that, fixed!

RakuNana | 2023-06-15 04:47

:bust_in_silhouette: Reply From: RakuNana

I Solved it, I created a list of positions for the player units and enemy units,These are stored when they are instanced to the scene. I then created a method that stores the selected player unit and selected enemy unit list, and name of the unit. I then compared both list to each other. If the list both have any of the same positions, They are colliding, and the name of the opposite unit is shown!