Hello, I’m asking if there is any way to check what was the first thing/instance that has entered an area even if there was a multitude of these specific things/instances that had entered that said area all within the same time(granted there is a bit of frame/millisecond delay)? I really only want to get the 1st thing that comes through, and disregard the others whilst using Area3D.
If you want to check what is the first thing that comes in, I have no idea.
But if you want to see if something is imported for the first time, this method is suitable:
1- create new var:
var is_frist_time = true
2- add an if in top of function:
func ...(...):
if is_frist_time:
is_frist_time = false
#function for first entered
else:
#function for other
Thank you for this information, but my problem with the Area3D checker still remains. Here’s the code for reference (which I should have put in the original post):
func _on_bomb_area_entered(area: Area3D) -> void:
var area_parent = area.get_parent()
var area_array = []
var count = area_array.insert(0, area.get_parent())
print(area_array[0])
#print("VALUES: ", area_parent)
for i in area_array:
if area.is_in_group("normTiles"):
#print(i.position)
self.position = i.position
#print(area_count)
else:
print("nothing")
Which has an output of this when another tile besides the original overlaps: Tile102:<Node3D#49492789534> Tile112:<Node3D#50969184630>
This is an example of the code, see that the get_parent() gets both at the same time, even after trying to put one value into an index of an array. Is there any way to separate this? Or to iterate my problem again, get only the first thing/instance that comes through this function?
I needed to get the parent of the area that has been collided in order to get the position of the tile that the player stands on, so for the area_parent I use that to make getting the tile easier. But the problem with it is, if the player stands on two tiles at the same time, the placed bomb accounts for the first tile within the area_parent values which is the last of the output as seen here (and I have put additional information in red text for what my ideal output would be):
It depends on when you regard the “first” time.
Does it mean:
the first time ever?
the first time whenever the scene is loaded/reloaded?
For now, I would create a variable that holds the object, then populate it with the object instance that enters the area.
var entered_object = null
func _on_area3d_entered(object) -> void:
if entered_object: return # Return if there is already an object in area
entered_object = object # Save the object
for the question “what is the object”, this is answered by setting up the collision layer/mask correctly. Only things that should be detected, will be detected by the area3d.
by the way, i am not sure yet if you want to check for areas or actual bodies. if you want the body but track the area instead, this means you are dependent on object.get_parent() to get the actual body’s script.
For clarification, whenever the scene is first loaded.
Update: It was a fundamental problem with my placement of Area3Ds. They were overlapping with each other in the first place hence why the problem would happen. I’ve shrunk them a bit to give space before travelling onto another tile, and it resulted into what I had wanted in the first place (and had fixed another issue I was dealing with hahaha). Nevertheless though, I appreciate all that have helped! Thank you kindly .