Method similar to Unity's SmoothDamp?

Get help using Construct 2

Post » Wed Jun 13, 2012 11:26 pm

Is there a way to to something similar to Unity's SmoothDamp Method? The way it works is like this(leaving out some bits):
SmoothDamp(5,100,6)
And then it transition 5 to 100 over the course of 6 seconds. While returning the value every time it changes. So you could change opacity and such over the course of however long, smoothly. Anyone know how I can do this?
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Thu Jun 14, 2012 12:47 am

It can probably be done using a "advanced" lerp function depending if you want a regular increase or not ... using lerp the problem is the third parameter and math is my nemesis so ... i let "expert" give you a more complete answer ! ... it can perhaps be done using a "sin" too

A very interesting post (not as mine ;-p) about this kind of effects
interpolation

thanks for this very interesting post !

Perhaps something more simple ... if you add dt to a variable every tick, it adds 1 to this variable every second so consider "x" = "targetvalue-value" must be reach in 6 seconds perhaps :

every tick :
value = value + dt * (x/6) ?naelian2012-06-14 01:44:46
B
16
S
5
G
3
Posts: 298
Reputation: 5,240

Post » Fri Jun 15, 2012 9:48 pm

@DoubleElite you have found something else ? ... my answer is good, not good ? and why ?

Sorry but people requesting for help and forgetting they have do so ... it's really something i don't like at all ...
B
16
S
5
G
3
Posts: 298
Reputation: 5,240

Post » Fri Jun 15, 2012 10:41 pm

I tried to experiment with your idea to lerp() expression, well it didn't, maybe i did wrong, anyways i would love to see a proof...
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Fri Jun 15, 2012 11:02 pm

It depends on your interpretation of "smooth".
Lerp offers a transition similar, but its a curve so the start, and end can be slower than the middle. Ease out, ease in if you will.
Also you cant really do exactly 6 seconds, nor should you expect that in a system that goes on frame rate.
However, if that's not terribly important, you can get a close approximation using dt.
I'd suggest some experimentation with variables as triggers if you absolutely have to that kind of precession.
Just be ready for frame skips.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Fri Jun 15, 2012 11:10 pm

Try this to have a sprite change it's x from 5 to 100 in 6 seconds after a click.

global variable start_value=5
global variable end_value=100
global variable duration=6
global variable start_time=0

+On click
--- set start_time to time

+time < start_time+duration
--- Sprite: set x to lerp(start_value, end_value, (time-start_time)/duration)

+time >= start_time+duration
+trigger once
--- Sprite: set x to end_value
B
79
S
24
G
54
Posts: 4,751
Reputation: 40,765

Post » Fri Jun 15, 2012 11:40 pm

You could try taking a look at this behaviour easytween by lunarray
B
27
S
9
G
5
Posts: 108
Reputation: 5,744


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests