Circular QTE-like button press

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Kinmoku
Veteran
Posts: 447
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Circular QTE-like button press

#1 Post by Kinmoku » 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 :)

rames44
Regular
Posts: 156
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Circular QTE-like button press

#2 Post by rames44 » Thu Oct 31, 2019 11:50 am

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

User avatar
Per K Grok
Miko-Class Veteran
Posts: 556
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1
Projects: Defenders of Adacan Part 2
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Circular QTE-like button press

#3 Post by Per K Grok » Thu Oct 31, 2019 5:45 pm

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. :)
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

User avatar
Per K Grok
Miko-Class Veteran
Posts: 556
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1
Projects: Defenders of Adacan Part 2
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Circular QTE-like button press

#4 Post by Per K Grok » Sat Nov 02, 2019 4:01 am

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
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

rames44
Regular
Posts: 156
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Circular QTE-like button press

#5 Post by rames44 » 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.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 556
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1
Projects: Defenders of Adacan Part 2
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Circular QTE-like button press

#6 Post by Per K Grok » Mon Nov 04, 2019 1:21 pm

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. :)
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

User avatar
Kinmoku
Veteran
Posts: 447
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Circular QTE-like button press

#7 Post by Kinmoku » Mon Nov 25, 2019 5:24 am

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

Post Reply

Who is online

Users browsing this forum: Google [Bot]