Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dumuz |
On AI node:
func _process(delta):
var distance2opponent = self.transform.origin.distance_to(get_node("../Player").transform.origin)
if distance2opponent < 5 and $Tween2.is_active():
$Tween2.stop(Tween)
round(translation.z)
print(distance2opponent)
On Player node:
func _process(delta):
var distance2opponent = self.transform.origin.distance_to(get_node("../AI").transform.origin)
if distance2opponent < 5 and $Tween1.is_active():
$Tween1.stop(Tween)
round(translation.z)
print(distance2opponent)
I tried using this script to have two meshes (A.I. and Player) check their distance between each other. If they get within 5 units of each other they’re supposed to stop
, but they just end up ignoring it can going right through each other. They’re both only moving on the z axis.
I know the functions are being called because it prints the distance like it’s supposed to a bunch of times till getting to 0 (When the two meshes stop based off the tween). But round
is ignored, as well as the stop
call. There are no errors popping up in the debugger.
HALP!
I notice that in the A.I. enemy, the line var distance2opponent = self.transform.origin.distance_to(get_node("../Player").transform.origin)
has the property “transform”. Maybe it needs to be ”global_transform"?
Ertain | 2019-11-28 21:45
Nope, just does the same thing. The nodes understand where each other are; I can see it in the debugger, because it prints the distance2opponent
variable, every frame. But they don’t stop, they ignore the rest of the commands.
Dumuz | 2019-11-28 22:24