Gravity

For questions about using Classic.

Post » Tue Jul 19, 2011 9:45 am

I couldn't get distance function. How can you divide a value which includes 4 values to a value ?

distance(Sprite2.x,Sprite2.y,Sprite.x,Sprite.y)/global('maxdistance')

Is there any document that I can find all usable functions on construct with their meanings ?

Thank you very much.
B
7
S
1
G
1
Posts: 76
Reputation: 904

Post » Tue Jul 19, 2011 9:50 am

i didn't know clamp or lerp till construct

but yeah clamp is like this:
clamp(input,lowest,highest)
it just gives you back the 'input' number, unless it's out of the range of highest and lowest. if it is, then it just forces it into that range

clamp(5,0,10)==5 (not lower than 0 or higher than 10)
clamp(3,0,10)==3   (not lower than 0 or higher than 10)
clamp(-3,0,10)==0 (too low, force it into range)
clamp(1000,0,10)==10   (too high, force it into range)


lerp(a,b,t)
lerp gives you a number between a and b
and it uses t to determine how far along it is between a and b
think of t like a percentage, but with a decimal in front of it
t==0 is like 0%   (t==0)
t==1 is like 100% (t==1.00)
t==0.54 is like 54%
t==0.3 is like 30%

lerp(a,b,t)
so if t is at 0 you get back 'a'
if t is at 1 you get back 'b'
and if t is anything in between 0 and 1, it's that far along the line between a and b

lerp(0,4,0)==0
lerp(0,4,0.25)==1
lerp(0,4,0.50)==2
lerp(0,4,0.75)==3
lerp(0,4,1)==4

I made a short tutorial about lerp that helps some people if the explanation didn't work, it's more interactive and visual:
http://69.24.73.172/scirra/forum/viewtopic.php?f=8&t=8735lucid2011-07-19 11:39:17
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jul 19, 2011 10:03 am

posted something just now without noticing this post, so read the post above if you're just reading this
[QUOTE=Spider_hip] I couldn't get distance function. How can you divide a value which includes 4 values to a value ?

distance(Sprite2.x,Sprite2.y,Sprite.x,Sprite.y)/global('maxdistance')

Is there any document that I can find all usable functions on construct with their meanings ?

Thank you very much.
[/QUOTE]

all the usable expressions you can get when you're in that expression editor(anywhere you can type these expressions)
doubleclick on the system icon, and it gives you a list
this list is also handy:
http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions


the distance expression returns the distance between two points
distance(point1x,point1y,point2x,point2y)
it's the same as using the pythagorean theorem, but that doesn't matter, because you don't need the details to make it work. but it returns one value representing the distance between the first and second point
so you can use it to find out how far away two objects are in pixels



as far as why use the division problem,
when you divide any value by some maximum value, you get a decimal value that represents what portion of the whole you have like
let's say your max is 4
0/4==0
1/4==0.25
2/4==0.5



look familiar?   it works in alot of situations to give you that perfect value for t in
lerp(a,b,t)



we used clamp, because we want to force the values to stay between 0 and 1, so the speed we choose for things getting sucked in the black hole won't get blown away from the black hole when they get too far because
lerp works with larger and smaller numbers for t
like lerp(0,10,2.0)==20
or lerp(10,0,2.0)==-10

or lerp(0,10,-0.5)==-5lucid2011-07-19 11:43:48
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jul 19, 2011 10:31 am

Wow thank you very much for spending your time to explain all these stuff to me. You have explained all of them perfect. I will read twice, three times, until It sticks in my mind :) Really amazing to know these expressions, functions and especially to use them in neccessary areas. If I had knew these lerp and clamp before, I'm prety sure that I couldn't think of using them for this gravity effect :)

See you soon :) I'll try and play with these. Thank you for teaching me :)
B
7
S
1
G
1
Posts: 76
Reputation: 904

Post » Tue Jul 19, 2011 11:37 am

glad it helped. enjoy!lucid2011-07-19 11:37:47
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Oct 18, 2011 11:20 pm

i think this thread is kinda old, so i dont know if i should bump it. but i'm just gonna ask anyways i guess. can i?
B
6
S
1
G
1
Posts: 52
Reputation: 858

Post » Wed Oct 19, 2011 1:02 am

You can bump it if you have something to add to the discussion. Which you kind of left out of your post.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests