0 votes

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!

in Engine by (349 points)

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"?

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.

1 Answer

+1 vote
Best answer

$Tween2.stop(Tween)

This looks incorrect, unless you really have a variable named Tween containing the object your tween is animating (which would conflict with the class of the same name). Check my answer in https://godotengine.org/qa/56132/why-does-tween-stop-need-an-argument

by (27,964 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.