|
|
|
|
Reply From: |
Adam_S |
I think your code should be like
if bodies.is_in_group("vehicle"):
bodies.call("gotshot", 35)
Instead of
if body.is_in_group("vehicle"):
body.call("gotshot", 35)
I changed it to that, it looks like this now:
if !exploded:
for bodies in $Area2D.get_overlapping_bodies():
if bodies.is_in_group("vehicle"):
bodies.call("gotshot", 35)
print(bodies)
exploded = true
But it’s still not working :S
I added a print to see if it’s event detecting both cars im using to test, but it isnt.
Tato64 | 2020-12-09 02:37
I did a quick test and it seems like when _on_Area2D_body_entered()
gets called for the first vehicle, get_overlapping_bodies()
only contains one of your vehicles, and when it gets called for the other vehicles your exploded
variable is true
and your code will not be executed.
You can see this when just printing the overlapping bodies
func _on_Area2D_body_entered(body):
print($Area2D.get_overlapping_bodies())
If that’s really the case (not sure, because I’m tired) and you don’t solve this, I will look at this tomorrow.
Adam_S | 2020-12-09 03:15
Hmmm… it prints:
[[KinematicBody2D:1731]]
[[KinematicBody2D:1731], [KinematicBody2D:1767]]
Does this mean it’s detecting one twice?
Edit:
This code works almost perfectly:
func _on_Area2D_body_entered(body):
for bodies in $Area2D.get_overlapping_bodies():
if bodies.is_in_group("vehicle"):
bodies.call("gotshot", 35)
$Area2D.queue_free()
BUT, it is in fact detecting (and damaging) one of the cars twice
Tato64 | 2020-12-09 03:46
It means that _on_Area2D_body_entered(body)
is called twice, but at the first time only one vehicle is in get_overlapping_bodies()
and your exploded
variable gets true
.
So your code won’t be executed for the other vehicles.
Adam_S | 2020-12-09 03:52
Oh my god, you’re right, how could i be so blind lol
Its called on body entered and there’s 2 bodies in there! :facepalm:
Ok, so… the problem lies in _on_Area2D_body_entered(body)
I tried removing it and putting the code somewhere else, but so far it isnt working as intended.
I think i’ll just make a new node for the Area2D that does all this on “ready” and instance it inside my mortar.
But tomorrow, because it’s 3AM here and i have spent way too much time trying to figure this out.
Thanks for the insight!
Tato64 | 2020-12-09 05:53