Learning Expressions.

Get help using Construct 2

Post » Wed Nov 09, 2011 1:04 pm

Hi there, does anyone know a tutorial to understand Expressions?

I dont 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 its to set X.

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

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

Thanks a million :)
B
18
S
4
G
5
Posts: 149
Reputation: 4,498

Post » Wed Nov 09, 2011 1:40 pm

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.bUbU872011-11-09 13:41:00
B
5
G
2
Posts: 11
Reputation: 1,181

Post » Wed Nov 09, 2011 1:42 pm

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.
B
5
G
2
Posts: 11
Reputation: 1,181

Post » Wed Nov 09, 2011 1:54 pm

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 :)
B
18
S
4
G
5
Posts: 149
Reputation: 4,498

Post » Wed Nov 09, 2011 5:20 pm

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

Yann2011-11-09 17:21:48
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Nov 09, 2011 7:03 pm

Thanks.

Will read that with attention :)
B
18
S
4
G
5
Posts: 149
Reputation: 4,498


Return to How do I....?

Who is online

Users browsing this forum: Braus, RickUSBstick, Yura G and 18 guests