0 votes

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.

Godot version 3.2.3
in Engine by (94 points)

1 Answer

0 votes

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.

by (7,530 points)

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 :)

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

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.