Page 1 of 1

Circular QTE-like button press

Posted: Thu Oct 31, 2019 7:09 am
by Kinmoku
Hi all,

Is it possible to create a circular QTE-like motion for a button press in Renpy? There's a moment in my game where you have to use a key to unlock a door, and I thought it'd be more immersive to turn the key in a circle to do so (instead of pressing a button).

I think I'll want to use drag for this, but I don't know how to set it up to work on rotation. I'd like the door to unlock when the key has been rotated 360 degrees clockwise but have no idea how to do this. Has this been done before?

Thanks :)

Re: Circular QTE-like button press

Posted: Thu Oct 31, 2019 11:50 am
by rames44
In theory, you could do this with a custom Displayable, because in there you have access to the low level mouse events. You’d have to write the code to track the position of the mouse and decide what it had followed the path you wanted. Probably not trivial...

https://www.renpy.org/doc/html/udd.html

Re: Circular QTE-like button press

Posted: Thu Oct 31, 2019 5:45 pm
by Per K Grok
Kinmoku wrote: Thu Oct 31, 2019 7:09 am Hi all,

Is it possible to create a circular QTE-like motion for a button press in Renpy? There's a moment in my game where you have to use a key to unlock a door, and I thought it'd be more immersive to turn the key in a circle to do so (instead of pressing a button).

I think I'll want to use drag for this, but I don't know how to set it up to work on rotation. I'd like the door to unlock when the key has been rotated 360 degrees clockwise but have no idea how to do this. Has this been done before?

Thanks :)

I think you could do it like this.

You have an image of your lock. You have images of the key at different degrees of turning. The middle of your lock is your centerpoint.

You set up two circles with that centerpoint as the middle. The outer circle the mousepointer need to be inside to turn the key.
The smaller the mousepointer must be outside to turn the key.

This will give you a track that the mousepointer can go around.

You can set up the circles with this function


Code: Select all

    def inCircle(pointX, pointY,gX,gY,distance):
        xDist = pointX-gX
        xDist=math.fabs(xDist)
        yDist = pointY-gY
        yDist=math.fabs(yDist)
        xyDist = (xDist*xDist)+(yDist*yDist)
        if distance >= math.sqrt(xyDist):
            return True
        else:
            return False

You need a label that repeats itself every 0.2 second (or something like that).

You need to check that the mousepointer is inside the track and the angle of the line between the centerpoint and the mousepointer.

You can get the angle with this.

Code: Select all

    python:
        mX=renpy.get_mouse_pos()[0]
        mY=renpy.get_mouse_pos()[1]

        xD = centerX-mX
        yD = centerY-mY
        
        turnDegree = math.degrees(math.atan2(yD, xD))+180

The turning starts when the mousepointer goes over the 0 point and continue as long as the degree keeps increasing, until a turn is completed and the door opens.

Not tested but I think it should work.

I will probably see if I can work something like this into my wip game. :)

Re: Circular QTE-like button press

Posted: Sat Nov 02, 2019 4:01 am
by Per K Grok
Kinmoku wrote: Thu Oct 31, 2019 7:09 am Has this been done before?
I got interested enough to try out my idea and make a little video of my test, that now is in the cook book with the code for my script.
viewtopic.php?f=51&t=57267

Re: Circular QTE-like button press

Posted: Sun Nov 03, 2019 12:58 pm
by rames44
Elegant. I hadn’t thought of using the pause command to essentially set up a polling loop. Kudos.

Re: Circular QTE-like button press

Posted: Mon Nov 04, 2019 1:21 pm
by Per K Grok
rames44 wrote: Sun Nov 03, 2019 12:58 pm Elegant. I hadn’t thought of using the pause command to essentially set up a polling loop. Kudos.
I don't think my style of program ever could truly be described as elegant, but I thank you from the bottom of my heart for trying. :)

Re: Circular QTE-like button press

Posted: Mon Nov 25, 2019 5:24 am
by Kinmoku
This is awesome! I got side-tracked and completely forgot I posted about this, but thank you for the help! I'll definitely be implementing this :D