How do I Implement CLAMP ?

2 favourites
  • My Question: How do I change the position of the Knobs on the Layout WITHOUT changing their values, and also... make them stay based on their original default PIN position?

    You have this formula to set knob position to its value:

    lerp(Slider.ImagePointX(1), Slider.ImagePointX(2), unlerp(Self.Minimum, Self.Maximum, Self.Value))

    So just add this event below all other slider events:

    On every tick
    Knob is NOT dragging
    	Knob set Y to Slider.Y
    	Knob Set X to lerp(Slider.ImagePointX(1), Slider.ImagePointX(2), unlerp(Self.Minimum, Self.Maximum, Self.Value))
    

    With this approach you don't need to pin/unpin the knob all the time. When it's not being dragged, it will stick to its correct position on the slider. So Pin behavior needs to be removed.

    Also, I suggest using containers. (see my original demo)

  • at first I was setting the knobs to the slider every tick like that, but as you dragged the panel around there was a slight lag that didn't look very good.

    so that is why I pinned the knobs to the panel at the start of a drag, and unpinned them on a drop.

    Alon, to solve the first problem, before you move the panel, pin the knobs to the panel. Then on Knob drag start, unpin the knob.

    by changing the wait from 0.25 to 0.1 is making it wait less time, not more! try 0.5 seconds.

    also, making the panel invisible does not disable it - you can still drag and drop it, and the sliders will still work if you happen to click on one. it is better to move it off screen if you want to hide it.

  • just tried it out, and unpinning a knob on the start of a drag will also solve the timing issue.

    whenever you move the panel by drag and drop, or manually changing its position, pin the knobs to the panel first. And only unpin when you start to drag a knob (or when you update the knob position when an object it selected).

  • AllanR You are right, knobs are lagging if you set their position to slider's position on every tick. But this lag is actually caused by Pin on the slider, because Pin behavior updates object position at the very end of the tick.. If you set the slider position with events too (not with Pin), then there is no lag:

    dropbox.com/s/plp4jqq6d8a858x/slider_knob_nopin.c3p

  • thanks! I knew I had done something very similar recently that didn't have any lag - I must have done what you did in that example. I knew there was a lag if you pinned something to another object that was pinned to something else, but thought if you manually positioned the second object it might avoid that issue.

    now I know - either pin everything to the same object, or manually position if there is a hierarchy.

  • I love to see a topic about slider control and effects. Thanks for sharing this info. I will try to bring all that info back into c2.

    I also want to implement a range slider & input fields for each slider to limit the min or max values to choose from.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks AllanR and dop2000 for the great findings and experiments, this is interesting indeed!

    From quick test like I did last time (moving the panel CRAZY FAST) it seems VERY STABLE.

    To be honest a bit confusing as I look at the code with all the new things (especially with that funny word "LERP" that I have no idea what it does or what it does on the code, what's it's purpose or anything about LERP! but it's a funny word... (feel free to explain it to me based on our example if you like).

    .

    2nd thing, I've tried to replicate the latest C3 update file by dop and it's "ALMOST" working, I still couldn't find after trying to find where the problem is after trying to put some browser logs on the LERP sections which I notice happens every tick (keep raising the numbers) but still when clicking the knobs I didn't see any difference.

    I looked on my own code to see where it could be but nothing is related to it from what I looked (beside looking carefully manually) I used the Ctrl+F to search for "Knob" because I'm guessing it is something about it. I also tried to Turn On / Of some lines to see what affect it, and I believe it's related to that LERP thing which I don't understand.

    It seems like it's doing something with the Y position of the above Knob which is strange, but this all code is overwhelming for me anyway, it could be that funny word "LERP" related or the dy instance variable, I don't know for sure

    It could be around this event:

    from my enable/disable testings, if I disable the 1st action on this event (look at the image below), the sliders stay at the same place (not following the panel) BUT! they don't have the "Y" Knobs position issue as shown above.

    What could it be?

    if it's related to the LERP thing I don't understand it so... any suggestions why it may happen on my code? or how should I debug to find the issue?

  • that would be a picking issue. each knob has to pick the correct slider before it can be aligned properly.

    lerp is a lot like clamp, you give it a start point, and an end point, and then what percentage of the way between the two it currently is.

    so when the percentage is zero, it will be at the start point, at 100% it will be at the end point, at 50% it will be half way between the two.

  • lerp is a lot like clamp, you give it a start point, and an end point, and then what percentage of the way between the two it currently is.

    so when the percentage is zero, it will be at the start point, at 100% it will be at the end point, at 50% it will be half way between the two.

    So basically, Clamp: will give 2 points: min - max?

    and Lerp will give 3 points: min, percentage, max?

    I'm not sure if I understand but I was curious.

    that would be a picking issue. each knob has to pick the correct slider before it can be aligned properly.

    I just replicate the same code and the only difference that matters the code is the image I shared above when I disable it, I don't have anything extra to for each or the sliders/knobs beside the same code that's why I can't find the issue.

    This is the only part that affect the weird knobs movement on the Y but I don't know why... or more important I can't find the problem in order to fix it (if I can fix it at all of course).

    It's probably something on my code that I can't relate because as I mentioned on the last post I did search manually and with the Ctrl+F to try find anything related.

  • Yeah, there is nothing mysterious about clamp, lerp and unlerp functions, they are well documented and you can google a million examples of their use.

    About the problem you are having - I'm guessing you didn't put knob and slider into a container. If you don't want to use containers for some reason, you will need to pick the correct slider when setting position of each knob.

  • YUP! it was the Containers! :)

    I never used containers before it sounds like a VERY useful tool, like hierarchy child-parenting in compositing I guess (from reading the manuals) but in practice it's the best way to learn.

    I wonder if it's a only C3 feature like Families.

    The Tank example is nice but like most of the manual things are not very clear for example what about changing all values/instance variables to absolute or relative of all contained objects at the same time, or just location, and why not using families if it's grouping others, I have so much more to learn... yeah, I'm confused, I have much more to learn, but never mind that... one by one, unfortunately my brain isn't big enough.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)