How do I round lerp to the nearest integer?

Get help using Construct 2

Post » 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
13
S
6
G
1
Posts: 149
Reputation: 1,960

Post » Tue Apr 12, 2016 1:37 am

Why not just add or subtract one when you press the arrow keys?
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » 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.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,611
Reputation: 61,643

Post » 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
13
S
6
G
1
Posts: 149
Reputation: 1,960

Post » 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.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,611
Reputation: 61,643

Post » 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
13
S
6
G
1
Posts: 149
Reputation: 1,960

Post » Tue Apr 12, 2016 10:00 pm

Update to the latest stable then.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,611
Reputation: 61,643


Return to How do I....?

Who is online

Users browsing this forum: Armench, Artcadev, farsen, mariusvm, TheRealDannyyy and 11 guests