Change texture not working correctly.

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

So I’m working on this project where dots infect other dots so they turn green. Alse when they touch a red dot they turn green as well. The dots get spawned every couple of seconds. But now I think the problem is that the dots can only get infected by other dots spawned before them.

This is the code wich detects the collision and turns the dots green.

func _on_Human_body_entered(body):
	if body.get_name() == "Virus" or body.get_name() == "InfectedHuman":
		var mysprite = $HumanSprite
		mysprite.set_texture(infected_sprite)
		get_node(".").set_name("InfectedHuman")

Is there a way to fix this problem so that dots can be infected by dots spawned after them?

:bust_in_silhouette: Reply From: njamster

Checking a bodies name is very unreliable, see my comment over here. Add your dots to a group instead and then check for it with body.is_in_group("<GroupName>").

Yesss problem fixed! Thanks a lot for your time/help!!

rubendw03 | 2020-03-22 11:11