# Method similar to Unity's SmoothDamp?

Get help using Construct 2

### » 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,875

### » 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

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: 296
Reputation: 5,236

### » 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: 296
Reputation: 5,236

### » 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
87
S
21
G
18
Posts: 3,045
Reputation: 20,989

### » 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.
B
160
S
48
G
80
Posts: 7,239
Reputation: 61,506

### » 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
75
S
21
G
48
Posts: 4,667
Reputation: 37,199

### » 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