Rotating pointer behaving weirdly

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

I am trying to make a pointer that circles around the player and points towards the mouse cursor and doing so using a simple algorithm that finds a vector between the cursor and the pivot point and then normalizes it to set as the pointer position.

This solution works perfectly until I move my player from the starting position. The pointer still moves to the correct spot but it rotates weirdly and doesn’t follow the cursor at all. Anyone know why this might be hapening?

Program in action

extends Node2D

onready var pointer: Sprite = get_node("../Sprite2")
var pointer_position: Vector2 = Vector2()
onready var pivot: Node2D = get_node("../Pivot")
var pivot_position: Vector2 = Vector2()

var midpoint: Vector2 = Vector2()

func _process(delta: float) -> void:
    pointer_position = pointer.position
    var cursor_pos = get_local_mouse_position()
    if pointer_position.distance_to(cursor_pos) > 
pointer_position.distance_to(pivot_position):
	pointer.look_at(cursor_pos)
midpoint = Vector2((pivot.position.x + cursor_pos.x)/2, (pivot.position.y + 
cursor_pos.y)/2)
midpoint = midpoint.normalized()
pointer.position = Vector2(pivot.position + (midpoint * 30))

Try using global cordinates when getting pointer and mouse positions.

magicalogic | 2022-07-09 16:34