0 votes

I want a cursor that tilts depending on the direction your moving your mouse. I got it done in construct a long time ago but I wanted to make it in Godot fixing the problems I bypassed with wacky solutions back then.

The hand sprite detach from the mouse position when the mouse starts moving and that's how I got the angle I needed to rotate the hand and depending on the distance from the cursor the sprite would move faster.

enter image description here

My Idea this time was to take a position in the same direction the mouse is moving but further away depending on the speed of the mouse, then make the hand look at the reference point.

I started by setting the reference point at get_global_mouse_position() + Input.get_last_mouse_speed() and it works but the inertia is too strong.

func _process(delta):

func _draw():
draw_line(get_global_mouse_position(), marker_vector, Color(255, 0, 0), 1)

I drew a line and realised that even thought draw is called every frame the position of the point is a bit chunky and it doesn't look as smooth as I was thinking. Lastly when I printed get_global_mouse_position() + Input.get_last_mouse_speed() the resulting Vector2 had nothing but integers on both axis. I don't know if this is the cause of the chunky movement but I can't come up with anything else.

If i ditch the get_last_mouse_speed() method how can I get a vector2 in a direction x distance away from the mouse position

in Engine by (235 points)
retagged by

I dont get the whole concept. But let answer you the last question:

how can I get a vector2 in a direction x distance away from the mouse position

Var result =  mouse_position + direction.normalized() * distance

Result is vector2 a point distance away from mouse in direction
Mouse_position is vector2
Distance is float

There you go

Normalized works I've read more about vectors and know I think I get it normalize makes the vector length 1 and keeps the direction. Unfortunately I came up with new problems I'll need to read more about vectors.

Thanks for the help.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.