![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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