Storing distance into instance variable

Get help using Construct 2

Post » Wed Mar 04, 2015 7:34 pm

Hello, how can i store the distance between 2 points into a instance variable?
B
6
Posts: 35
Reputation: 326

Post » Wed Mar 04, 2015 8:53 pm

There is a built in method called distance. Below is it's usage:

distance(Position1.X, Position1.Y, Position2.X, Position2.Y)

This returns a decimal value of the length of the line between the 2 points. If you need a distance along a path which changes directions, you could simply sum up all the values of the distances between each change of direction:

distance(p1.X, p1.Y, p2.X, p2.Y) + distance(p2.X, p2.Y, p3.X, p3.Y) + distance(p3.X, p3.Y, p4.X, p4.Y) etc...

To get more information, do a search in the manual. You will find all you need to know about the distance method.
B
38
S
12
G
11
Posts: 329
Reputation: 7,708

Post » Thu Mar 05, 2015 6:19 am

Thanks.
B
6
Posts: 35
Reputation: 326


Return to How do I....?

Who is online

Users browsing this forum: ezrubiera, mrline and 9 guests