#What is this error?

16 messages · Page 1 of 1 (latest)

odd talon
#

you can try to "print(_target.global_position)" and "print(global_position)" to figure out which of the two exists or not. Alternatively, when the game crashes, there should be in the debugger a list of all variables currently active for the script. There you can check whether "_target" has the value null or not

late jungle
odd talon
#

why are you printing "_target" in the init function? You need to do it within your "rotate_to_target" function, because your "_target" is only defined within that scope

#

you should do it just before you create the var direction

late jungle
#

It is defined

odd talon
#

then, why do you call "_target" as an argument in the function?

late jungle
#

I don't have to call it?

odd talon
#

if you don't want to change its value, then no, you can simply call "rotate_to_target(delta)" and then do it exactly as you have it there. Alternatively, which I assume is the problem, is that there is no target defined, right?

#

If _target is never specified, then I would suggest you to use a different variable name and assign _target to that name (for example "set_to_target" and then "_target = set_to_target", smt like that)

late jungle
odd talon
#
  1. Do you have a reference to the dummy? from the five lines of code you showed, I can only assume that _target has no value assigned to it
  2. When calling the function, do you have a reference to the dummy as an argument? If not, remove the parameter (you can still access "_target" inside the function if you define _target at the start of the script). This is of course assuming you've always shown snippets from the same script. Else, it'll become more complicated because you'll have to show where you call that function and what you pass as arguments
late jungle
odd talon
#

yes, but that won't do anything? "var _target : Dummy" only tells the game "create this variable called _target. This variable can only take as a value something that is of the class Dummy." The game still doesn't have a reference to the dummy that exists in your game world.

late jungle
#

Ohhh

late jungle
#

So how to create the reference to the dummy?😖

odd talon
#

There are several ways. One way is to get the hard path to it and assigning it when declaring the variable. There are two options you have right now. Either you show me your scene tree of the game scene, or you watch the "survivor game" tutorial by gdquest (look in #free-godot-courses ) where they also have something like this (where the gun rotates to enemies)