Move() and cubic functions

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.
Message
Author
monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Move() and cubic functions

#1 Post by monele »

I've just started looking into this. Here's what I want : instead of using a simple linear interpolation as Move does right now, I'd like either a Move with some "function" option, or simply other Moves using something else than a linear function.
What I have so far : in renpy.display.layout I found Motion, Move and Interpolate. I see where the interpolate function is and that's exactly what I'd like to change by offering others than this one.

What's said though, is that the functions need to be pickleable... Interpolate also being a Class, I wonder if there's a way to define these in the script ô_o... I'm a bit afraid I'd have to make the changes in the Ren'Py code itself ^^;... Wouldn't be too horrible in a way but uh... I'm afraid I'll break stuff XD.

So yea, I'll try things right now but in the meantime, I wouldn't mind precisions on how I could work this out.

Of course, the overarching goal of this is to allow movements to start out slow, then speed up, then slow down, and other things like that, allowing smoother animations in the end ^^

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#2 Post by PyTom »

Well, you can just copy the definition of Interpolate into a python block inside an init block, and change it to your liking. Functions defined inside an python (but not python hide) block inside an init block should be pickleable. What happens is that python stores the name of the function or class, and then the system needs to look it up again after unserialization. Since this happens after the init phase, everything will be there and things should work.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#3 Post by monele »

I'll say yay then ^.^. Thanks.

Now to remember my maths and find how to have progressive deceleration @_@.... (and turn all this into a working interpolation function ? *explodes*)

EDIT : Acceleration works, booya X3... *easily made happy when it comes to maths...*

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#4 Post by monele »

Ok, made this work. Do you think anyone would be interested in this ? Could it even be added to Ren'Py ? So far I have "ease" using power functions (quadratic, cubic, etc...), circular functions and sinusoidal functions.
Not being good at maths, I only managed to have a variable value on power functions. I don't know if it's possible with the other ones.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

#5 Post by Watercolorheart »

^ :O

I have no idea what you just said. Well, I do actually because I went all the way up to Calculus, but what I mean is that I'm not sure how that relates to movement ...

I didn't know that functions were pickleable ....... don't they taste like brine then? D:

Alessio
Miko-Class Veteran
Posts: 576
Joined: Fri May 07, 2004 9:40 am
Completed: GO! Magical Boy (2006), Angelic Orbs (soundtrack)
Projects: Cyberlin (in progress)
Location: Finland
Contact:

#6 Post by Alessio »

monele wrote:Do you think anyone would be interested in this ?
Sure! Non-linear movements are definitely a good addition.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

#7 Post by Jake »

BCS wrote:I have no idea what you just said. Well, I do actually because I went all the way up to Calculus, but what I mean is that I'm not sure how that relates to movement ...
He's talking about varying the speed of the movement transition over time - currently, if you just use the Move on its own, it moves with a fixed speed - effectively the "speed over time" graph is a zeroth-power (flat) function. If one were to use instead (for instance) a y=-1*x*x function (which produces a pleasing hump) with a suitable offset, it would be possible to have movement which started off slow (the left of the hump) sped up in the middle (the peak of the hump) then slowed to a halt at the end rather than the sudden and abrupt halt you get with the fixed-speed function.

I must admit, I'm pretty curious to see your code, Monele, even leaving aside that it would be a useful feature - wouldn't you need to make sure that the function you were using had a fixed and known integral between the start and finish points to be able to use it for interpolation readily? Or am I over-thinking the problem?

[EDIT: Unless... is the interpolation more of a "find my position between these two points at time t" thing, where you only need to know the maximum of the graph? I guess I should really look at the existing code first...]
BCS wrote: I didn't know that functions were pickleable ....... don't they taste like brine then? D:
No!

Vinegar! :P

'Picklable' just means that Python can save them, and thus Ren'Py can save a game in which they're used (which is pretty important, for obvious reasons)...
Server error: user 'Jake' not found

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#8 Post by monele »

http://monele.clearlyseen.net/Divers/easeExample.html

#1 : linear motion
#2 : with acceleration and then deceleration.

Smoothes out movements and makes things less... "blocky" ? ^^;. Like comparing a sawtooth wave with a sinusoidal wave.

There should be ways to simulate bounces and even elasticity this way. I'll try to use elasticity for explosions so it shakes less and less through time.

EDIT : Jake > I'll admit I don't understand half of what I've coded XD... But I didn't have any problem with interpolation. I just used what was already in there for linear movements... and yes it's a function returning the position based on time, start pos and end pos. Nifty maths actually ^.^. I just changed the very boring "t" into "t**2" and other things :)

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

#9 Post by Jake »

monele wrote:and yes it's a function returning the position based on time, start pos and end pos. Nifty maths actually ^.^. I just changed the very boring "t" into "t**2" and other things :)
Yeah, the more I thought about it the more I thought that I was taking a far too physics-based and far too not-really-easily-programmable approach to the question. ;-)
Server error: user 'Jake' not found

User avatar
DaFool
Lemma-Class Veteran
Posts: 4171
Joined: Tue Aug 01, 2006 12:39 pm
Contact:

#10 Post by DaFool »

monele...

1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.

No physics necessary :lol:

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

#11 Post by Jake »

DaFool wrote:1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.
This does mean distributing more graphics than you'd otherwise need to, and getting an animation that doesn't get any smoother as the rendering framerate increases, though... if it's simple to do it in code, it's a far neater solution. ;-)
Server error: user 'Jake' not found

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#12 Post by monele »

DaFool wrote:monele...

1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.

No physics necessary :lol:
Yes but that's not *FUN* :P. Why would I spend hours in front of my keyboard at night, trying to figure out how to define the quadratic function for easing out otherwise ? :P

No really, it works, and I've actually needed this *exact* thing for work today which is like... a sign from heaven ? XD
I'll try to optimize the classes and stuff (would like to have *one* function with a "function" parameter) and post this later tonight.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#13 Post by PyTom »

I'm thinking at some point I'll add a parameter to Motion, Move, and Pan that makes them distort time. (To be honest, I thought that parameter was already there.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

shaja
Regular
Posts: 73
Joined: Sun Oct 16, 2005 8:34 am
Contact:

#14 Post by shaja »

BTW, the tiny demo I came up with for Motion documentation brings a smile to my face. ;)
All about the cheesy humor.

http://www.bishoujo.us/wiki/Functions/Motion

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#15 Post by monele »

Lol ^.^. Didn't even realize you could make a custom function that easily :).

Btw, I also realize what I have with Ease functions can simulate simple curved movements too ^.^. We're far from the control of a custom bezier curve, but hey, it's something ^^;

Post Reply

Who is online

Users browsing this forum: No registered users