# How does the distance commands work?

0 Favourites
• 4 posts
• Having trouble finding/figuring this out, I know the distance command returns the distance between the X and Y of an object compared to another.

But how do I use this? I'm trying to save this distance value and compare it because half way to the distance of another object I want to do other stuff. So does anyone know of an easy to to remember all of this distance checking, its confusing me bad.

Basically, I want to check one objects distance from another, using the dist() function returns the distance in pixels between these two objects? So I can do math on it like this?

dist(myObject1.x, myObject1.y, otherObject2.x, otherObject2.y) < distancetestvalue

trigger event

will this do:

this distance from the object less than this range

and which object goes where , how do I remembher this stuff/ Anyone know of a beginners guide to programmer website that can explain this basic geometry/trigonometry to me? I canrt figure out atan2 either. I know they do what they do, but not why they do it or any special rules I should follow when using the commands.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• Well your explanation confuses me, while I understand..

distance(x1,y1,x2,y2) returns the distance in pixels between point 1 and point2

angle(x1,y1,x2,y2) returns the angle between point 1 and point 2

to get halfway between the two objects you could move something 0.5*distance() at angle()

another way would be to create an object at x=lerp(x1,x2,0.5) y=lerp(y1,y2,0.5)

If you use

dist(myObject1.x, myObject1.y, otherObject2.x, otherObject2.y) < distancetestvalue

it will check if object2 is within a radius of distancetestvalue of object1

• wow thanks alot for the explination but, im kinda confused, what does lerp do?

anyway, Iddint know the order was important for distance() and thanks for that. basically I want to check objects distances within radiuses, yes. But the other stuff sounds important too. I dont have a very good understanding of this so I'm trying to figure out all the distance functions since its important for me to know where stuff is.

• solved