Vector2 Rotation?

4.3

I’m trying to set the rotation of another node to be the same as another node, and this is the code I have for that:

func _physics_process(delta):
	$Arm1/Node2D.global_rotation = Vector2(sword.global_rotation)
	$Arm2/Node2D.global_rotation = Vector2(sword.global_rotation)

But when I try to run it it says that it’s an “Invalid call” and it’s a “Nonexistent ‘Vector2’ constructor.”

Is there a way to set rotation of two nodes to be the same, and do you use Vector2 to do it?

Why do you create a new Vector2?

sword.global_rotation should already be a Vector2 => you can set it directly, right?

1 Like

I took out the Vector2, which runs the code now, but I now realize that I think what I really need is for the $Arm2/Node2D to have the opposite rotation as sword, which I also don’t know how to do :confused:

Could you do this? Using the negative operator

$Arm1/Node2D.rotation = -sword.rotation
$Arm2/Node2D.rotation = -sword.rotation
1 Like

I had to change a couple other things in the code, but that worked, thanks!

One more question though, is there a way to only keep the x rotation?

There is no ‘x’ rotation in 2D. Maybe you intend to flip the sprite?

1 Like

Yeah flip the whole node, the only problem though (which I could live with if it it’s unfixable) is that when it’s rotated up, it gets rotated down and vice versa.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.