Position2D is not rotating

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

I have my player’s camera set on a Position2D node offset 50 pixels away from the player. I tried using the following code to rotate Position2D with my player:

extends Position2D

onready var parent = $'..'

func _ready():
	update_pivot_angle()

func _physics_process(_delta):
	update_pivot_angle()

func update_pivot_angle():
	var rotary = parent.inputVector.angle()
	rotate(rotary)
	print(rotary)

I use inputVector because it returns a value between 1 and 0 in Vector2 (with 1,0 being right, -1,0 being left, etc.)
The problem is that the value for rotary is 0 when going right, 3.14… when going left, and 1.57… and -1.57 when going up and down. And, it doesn’t change rotation no matter the direction.
Your help is appreciated! Thanks in advance.

The problem is that the value for rotary is 0 when going right, 3.14… when going left, and 1.57… and -1.57 when going up and down.

What do you want the output to be? This is called radians.

And, it doesn’t change rotation no matter the direction.

I don’t see anything wrong with the code. But I don’t know what values inputVector takes on. And how do you know that it’s not rotating? Does it have like a child sprite or something?

exuin | 2023-02-25 08:53

Thank you! You made me realize my mistake. I had attached the camera at (0,0) and offset the Position2D node at (50,0) which was spinning the camera but in place. I fixed it by placing the camera at (50,0) and the Position2D at (0,0). This rotated everything perfectly. Dumb move on my part.

pbij | 2023-02-26 16:14

:bust_in_silhouette: Reply From: pbij

The problem was I had attached the camera at (0,0) and offset the Position2D node at (50,0) which was spinning the camera but in place. I fixed it by placing the camera at (50,0) and the Position2D at (0,0). This rotated everything perfectly.