# How do I round lerp to the nearest integer?

Get help using Construct 2

### » Tue Apr 12, 2016 12:54 am

how do I round lerp to the nearest integer of 1?

I did a test to make the global test var increment and decrement depending on if I pressed left or right
and then when I don't press anything doing round(lerp(test,50,0.5))
but it seems to stop before it actually reaches 50 usually at 46 and 55

is there a way to make it always stop at b or in this case 50?
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

### » Tue Apr 12, 2016 1:37 am

Why not just add or subtract one when you press the arrow keys?
B
100
S
38
G
134
Posts: 5,555
Reputation: 85,323

### » Tue Apr 12, 2016 2:03 am

clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.

As R0J0 said, if you're looking for integers, you probably don't need to lerp.
B
60
S
30
G
132
Posts: 1,932
Reputation: 74,341

### » Tue Apr 12, 2016 2:34 am

its to compact code a little
I'm going to use it for slowly setting my animation frame back to one
since when I press left my ship tilts left(0) and when I press right my ship tilts right(2)
I want to be able to lerp it back to its middle frame (1)
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

### » Tue Apr 12, 2016 4:04 am

Something like https://www.dropbox.com/s/q0x1i46u72kfl ... .capx?dl=0 ?

If you're using round and you need to get it back center exactly, your lerp factor will have to be greater than 0.5.

Otherwise, use two sub events, one with floor and one with ceil depending on which way it is heading.
B
60
S
30
G
132
Posts: 1,932
Reputation: 74,341

### » Tue Apr 12, 2016 9:33 pm

sorry I can't open the project can you paste some code?
I don't feel like updating every time a unstable release comes out.
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

### » Tue Apr 12, 2016 10:00 pm

Update to the latest stable then.
B
60
S
30
G
132
Posts: 1,932
Reputation: 74,341