#How do i make a moving hand
1 messages · Page 1 of 1 (latest)
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 :/
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()
i got a bunch of errors when trying my best at following what you explained.
this is what i got:
Your code must be inside a function
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...

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.
oh, my bad
so im only going to write the
func update_hand_rotation():
var direction_to_mouse: Vector2 = .position.direction_to( get_local_mouse_position() )
under the
func _process(delta):
look_at(get_global_mouse_position())
?
i dont know if i understand
becouse if i do that
then nothing happenes
i shouldve picked a different hobby lol
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.
alright, i dont understand anything, nothing works, ill just scrap the idea and come up with something else 