0 votes

I've got the information on the point A location:

player_pos = $"/root/Global".player.get_position()

I've tried to put the angle needed for object B to rotate to point at A in a variable:

var angle_toplayer = get_angle_to(player_pos)

But it comes up with this error message:

Invalid type in function 'getangleto' in base 'KinematicBody2D (Sword.gd)'. Cannot convert argument 1 from Nil to Vector2

in Engine by (58 points)

Hi, that error means that when you set player_pos it was Nil. So, it looks like the expression $"/root/Global".player is not finding the correct position.

Check that this path really does point exactly to the player KinematicBody.

Alternatively, if this error happens immediately on start, maybe you are evaluating that before the player is active in the scene tree

I've now actually fixed it it was just that I didn't make the variable 'player_pos' a Vector 2 variable

1 Answer

+1 vote

Seems like you figured it out, just want this question not to show up as "unanswered", because it's solved.

by (127 points)
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.