0 votes
# Character look at mouse position
if playerTarget == null:
    rayHit.y = player.translation.y
    player.look_at(rayHit, Vector3.UP)

# Character look at target
else:
    mouseTarget = playerTarget.transform.origin
    mouseTarget.y += 1.5
    player.look_at(mouseTarget, Vector3.UP)
    gun.look_at(mouseTarget, Vector3.UP)

This is supposed to check if the mouse is pointed at an enemy. If so, player looks at enemy, if not, it just looks at the mouse position. Problem is every now and then, when testing the game, i get a null instance error after killing an enemy saying that playerTarget cant be found because its a null. Any ways to fix this?

Godot version 3.3.4.0
in Engine by (15 points)

1 Answer

0 votes
is_node_valid()

This is the only way to check for node, that might disappear during checking or iterating.

by (8,101 points)

Mind giving a sample. i tried it but gdscript cant find the function.

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 Frequently asked questions and 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 [email protected] with your username.