How do I make a rotating wheel control system which responds to flicks?

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

Hello!
I wanted to make a control system which responds to user’s flicks on screen(either with mouse or touches), such that, for example if I flick down the wheel should rotate in a clockwise direction and on flicking or swiping up, it should rotate in anti-clockwise direction.

But I don’t know how and where to start. Please help me out.
Thanks!

:bust_in_silhouette: Reply From: exuin

Since you can emulate mouse with touch by default, you should do this:

First, register the left mouse button in the Input Map. I have it registered as “click”. Next, put this code on the wheel:

extends Sprite


const ROT_MULT := 0.2

var previous:Vector2


func _process(delta):
	var current := get_global_mouse_position()
	if current != previous:
		if Input.is_action_pressed("click"):
			rotation += ROT_MULT * delta * (current.y - previous.y)
		previous = current

If you want to reverse the turning of the wheel, change the last term in the rotation addition to previous.y - current.y. Feel free to add friction to this if you want the wheel to gradually slow down after the player stops spinning it.

OK, that was another way of doing what I wanted, I did figure that out myself already, but how do I add that friction thing to stop it gradually, as if it was a real world wheel?
I’m using an Area2D with a CollisionShape2D as a child and the sprites as the child of it(CS2D), and just rotating that CS2D, just in case if you’d need that to help :slight_smile:

devAS | 2021-04-17 07:12

OK, I’ve done it, Thanks for your help.

devAS | 2021-04-17 14:49