Is there a way to do this?

Godot Version

4.6.2

Is there a way we’re I can have a node orbit my player but the orbiting node changes its degrees by where the mouse is.

I tried looking up a video, but all of them boil down to ‘look_at(get_global_mouse_position)’

Please, this is vital to my game

With so little information on what you actually want, it’s very difficult to help.
What’s wrong with using look_at and the mouse position? Do you have an example of what you’re trying to achieve?

1 Like

your orbiting node is in a 3d space, but mouse cursor is in 2d space. You can easily calculate an orbiting position but you must have to project your mouse cursor position to 3d space to “lookat” it.
may be you want the orbiting object to look at the object where the mouse is pointing at?

It’s a top-down Rouge-like. And the node orbiting is the weapon.

I want the node (weapon) to orbit around the player and would change where it’s orbiting around the player depending on the direction the mouse is from the player

From my understanding you want the sword to be a certain distance away from the player, and when the mouse moves, you would like to to move around in a circle around the player.

look_at can achieve this, but it is better for 3D games as it applies the rotation as well. The maths involved in 2D is trivial.

For the weapon, you can do the following.

  1. get the normalised vector of the mouse away from the node the sword is attached to
  2. multiply it by a set distance
  3. set the sword’s global_position to the result

Because the normalised vector will never have a magnitude greater than 1, it ends up effectively forming a circle. This blog post explains more if you’re curious about the maths: Introduction to vector math for game developers | GDQuest or Gabor Makes Games

You can attach the following script to your sword node to do this (make sure to select the node_to_track as your player):

extends Node2D

@export var node_to_track:Node2D
@export var distance_away_from_node_to_track:float = 100

func _process(delta: float) -> void:
	var tracked_node_to_mouse_position = get_global_mouse_position() - node_to_track.global_position
	if tracked_node_to_mouse_position.length_squared() > 0:	
		var mouse_direction = tracked_node_to_mouse_position.normalized() 
		global_position = node_to_track.global_position + (mouse_direction * distance_away_from_node_to_track)

The code above will do something like this:

animation of a circle spinning around a large square, a set distance away influenced by the mouse position

Node tree (Sub contains script):

Main is 100m×100m, and Sub is 50m×50m

If you want to improve the ‘feel’, look into interpolating the positions using e.g. slerp or lerp. This would add a bit of a delay to the movement but it could give some nice weight to the sword.

@gertkeno answered this in your previous thread with the same question. You even got the code.