Learning Expressions.

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi there, does anyone know a tutorial to understand Expressions?

    I don?t comprehend much of that part and I need a bit of knowhow.

    Like this for example 265 + sin(time * (360 / 5)) * 150 is to a platform to move horizontally and it?s to set X.

    The only thing I know is that 265 is the referral to the X axis. The rest I don?t understand a single bit.

    The ?help on expressions? link, inserted on C2, is an 404, so no help there lol

    Thanks a million :)

  • 256 should denote the position where the platform is per default.

    the sin(...) part takes care of moving the platform left and right. Basically it is an expression that "swings" between -1 and 1, see wikipedia (sinus) for details on that.

    "time" should be the game time starting from zero on game (or layout?) start. it takes care of the platform actually moving as time progresses, and the "* (360 / 5)" describes that the whole period of movement is split into 360/5=72 steps, each taking place in one time unit.

    150 is the distance by which it will move to each direction, meaning it will move 300px in total.

    actually as I'm only starting off with construct I would love for someone to confirm I got that right, too ;)

    EDIT: and I would also love to see a kind of comprehensive expressions catalogue by object/behaviour type.

  • also try just playing around with all the numbers (except maybe the 360 as it is derived from the nature of the sinus function). that should give you a good idea of what they do.

  • Yes, I've been playing around and I see what differences it makes if I change a number or so.

    What I really want is to understand the logic behind this, so I can do it without much trial & error, plus forums LOL

    thanks :)

  • Basically you can read that as :

    BasePosition + sin(phaseOffset + time * frequency) * Amplitude

    • BasePosition : is the middle of the movement as sin will go from -1 to 1
    • All that is in the sin function is modulo 360 that is to say if you have sin(361) it's the same as sin(1)
    • phaseOffset will offset the undulation (if you have 2 platforms with different phaseOffset they won't be on top at the same time.
    • time is the time in seconds since the begining of the game. The value inside the sin() will regurally increase... But remember, sin is modulo 360 so things will always ondulate
    • frequency : high number makes rapide undulations
    • Amplitude or Range of the movement around the BasePosition
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks.

    Will read that with attention :)

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