Whole number expressions

This forum is currently in read-only mode.
From the Asset Store
Create your own Behaviors in Construct 3 using events! Custom Expressions, Signals & Triggers Behavior Addon Pack
  • Is there a way to force Construct to round up an expression to the nearest whole number, rather than having a decimal number result? I'm moving an object around using loops and timedelta in order to keep things smooth. An example is in the deceleration event:

    ['Right' key isn't down] [Value 'X Value' is greater than 0]

    = [Player: Set 'X Value' to 'Player.Value('X Value')+(Player.Value('Deceleration')*timedelta) This subtracts a set deceleration value from the players X Value, and a loop is then run that moves the player according to the value of 'X Value'. The deceleration event should continue to subtract from 'X Value' until the value reaches 0 and the object comes to a stop. The trouble is, due to using the timedelta expression to maintain a smooth framerate, the deceleration value comes out as a decimal value, and so it sometimes doesnt reach the 0 value, meaning my object keeps moving a tiny amount even after it is supposed to have decelerated to a stop. Basically, is there some sort of expression I can use to force Construct to round up the 'X Value' to a whole number to ensure the value will eventually reach 0 through deceleration? Hope that makes sense, Cheers, Tom

  • the sys espression " Round"

  • Use round(number) in the expression editor. There's also expressions for rounding up and down rather than rounding to the closest, but I don't remember what they are - they're in the math section of the system object.

  • You could also add the subevent:

    + 'X Value' is less than 0

    -> Set 'X Value' to 0

    Or simply use the expression:

    Player: Set 'X Value' to: max(Player.Value('X Value')+(Player.Value('Deceleration')*timedelta), 0)

    Then you get the smooth floating point subtraction which never falls below 0. For small 'Deceleration' values, rounding may cause the movement to stop or become jittery, so you should prefer one of these methods.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The 'max' function works nicely, now everything runs smoothly whilst still subtraction to zero. Thanks!

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