XY Pad Modulation



  • Figured I should start a new thread instead of hijacking the CUBE one 🙂

    I'm working on a modulation system for the XY Pad using Timers, and I can get it to go from 0 to 1 on an axis, then change directions once it reaches 1, but it's using an if statement to check if the current value is less than the "destination" value, so the instant it swaps directions and goes back to <1, it changes directions to positive again and gets stuck in a loop

    example gif: https://i.gyazo.com/db19c1d398f82935a38cdee71cf5eb4e.mp4

    chaosXDrift.setTimerCallback(function()
    {   
        if (Slider_MovementXInvisible.getValue() < chaosXTarget)
        {
            Slider_MovementXInvisible.setValue(Slider_MovementXInvisible.getValue() + 0.1);
            Console.print("Going Up");
        }
        else
        {
            Slider_MovementXInvisible.setValue(Slider_MovementXInvisible.getValue() - 0.1);
            Console.print("Going Down");
        }
     
        Panel_MovementXYPad.repaint();
    });
    

    I just want a simple "sine" movement but I can't wrap my brain around the best approach for the logic, any help is appreciated 🙂



  • @iamlamprey said in XY Pad Modulation:

    Not sure exactly what you are trying to do but wouldnt this work?

    reg dirSet = 0.1;
    chaosXDrift.setTimerCallback(function()
    {   
        if (Slider_MovementXInvisible.getValue() < 0.1)
        {
            dirSet = 0.1;
        }
         if (Slider_MovementXInvisible.getValue() > chaosXTarget)
        {
            dirSet = -0.1;
        }
        Slider_MovementXInvisible.setValue(Slider_MovementXInvisible.getValue() + dirSet);
        Panel_MovementXYPad.repaint();
    });
    


  • @Lindon Yeh that does the same thing as my current script, the idea is:

    • Engine sets a "destination" XY coord
    • Timer checks if X and Y position are equal to, less than or greater than the destination
    • Timer either makes a new destination coord, adds 0.01 or subtracts 0.01 respectively

    It's like the timer isn't calling the new coordinate thing, even though i have console.print printing out both values and they do in fact match...



  • 7a01393c-4fd3-4844-8fab-7d8b8fccc804-image.png

    Every time they both equal 0.86, it should "reroll" the target, but it's not, could that have something to do with deferred callbacks or something? Or variable scope?



  • Is there a way to reduce the number of decimal points from Math.random() ?



  • Ok got it working 🙂 I had to change all of my values to integers since the rounding was causing some issues


Log in to reply
 

10
Online

1.3k
Users

4.2k
Topics

38.3k
Posts