Help (more rotation nonsense) making point A rotate towards point B

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By James122333

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 ‘get_angle_to’ in base ‘KinematicBody2D (Sword.gd)’. Cannot convert argument 1 from Nil to Vector2

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

AndyCampbell | 2020-12-26 00:22

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

James122333 | 2020-12-26 13:52

:bust_in_silhouette: Reply From: TheoTheTorch

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