#How do i make a moving hand

1 messages · Page 1 of 1 (latest)

hollow trail
#

so i want to make like a moving hand that follows your cursor, but it circles around my character in a strict circle so i can make like interactive swords or aiming with guns!

#

i already got the
func _process(delta):
look_at(get_global_mouse_position())
thingy btw
but it only makes it so the hand just spins in place :/

muted egret
#

This is a simple way by taking advantage of transform inheritance:

  • Make sure the hand points to the right, or offset its rotation so it points to the right by default.
  • Make it a child of the player/pivot point.
  • Move it to the right by how much you want it to be offset from the pivot.
  • Set its rotation like this:
func update_hand_rotation():
  #Get a vector pointing to the mouse.
  var direction_to_mouse: Vector2 = hand_node.position.direction_to( get_local_mouse_position() )

  #Apply its angle to the hand (with Vector2.RIGHT being angle = 0)
  hand.rotation = direction_to_mouse.angle()
hollow trail
muted egret
#

Your code must be inside a function

hollow trail
#

oh, my bad

#

i get an error: "Expected end of statement after expression, found "Identifier" instead."

with this line of code:
Vector2.RIGHT being angle = 0:
Sprite2D.rotation = direction_to_mouse.angle

#

i dont even know what that error means...

muted egret
#

Where does the "being angle = 0:" come from?

#

Oh, you copied my comment above without the hash #

#

Any line that starts with a hash is ignored by Godot, so they are used to write comments about the code for later reference.

hollow trail
#

oh, my bad

hollow trail
#

?

#

i dont know if i understand

#

becouse if i do that

#

then nothing happenes

#

i shouldve picked a different hobby lol

muted egret
#

I think you are just missing some fundamentals, i would also have a lot of difficulty without them.
But basically you want to put the code inside update_hand_rotation() as a way to organize it.
If you want that code to run, you can just do update_hand_rotation() inside _process() in order to call it and make it run.

hollow trail
#

alright, i dont understand anything, nothing works, ill just scrap the idea and come up with something else gddeadinside