Minimum/Maximum range expression?

0 favourites
  • 5 posts
  • Is there a way of limiting an expression to having a maximum number? A bit like how you can use random(4,84) or something to pick any number between two numbers, no lower than, say, 4 and no higher than 84, can you limit the result to be no higher or lower via an expression?

  • Do you mean something like clamp?

    clamp(x, lower, upper)

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

  • Do you mean something like clamp?

    clamp(x, lower, upper)

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

    Ahh, clamp, yes that's the one, I knew there was one! I'm trying this:

    Pin offsetX: PlayerAnimations.Angle/40[/code:garepmog]
    
    and I want to limit it so it doesn't shift the X too far if the angle of the player is too extreme, clamp will work okay?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ahh, clamp, yes that's the one, I knew there was one! I'm trying this:

    Pin offsetX: PlayerAnimations.Angle/40[/code:1smexmda]
    
    and I want to limit it so it doesn't shift the X too far if the angle of the player is too extreme, clamp will work okay?
    

    Yeap, I think it should.

  • If you only want an upper bound, min(x, limit) will not return more than the limit, effectively acting as only enforcing the upper bound. Likewise max(x, limit) will act as a lower bound.

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