# How do I test when two objects are perfectly overlapped?

Get help using Construct 2

### » Sat Nov 07, 2015 8:48 pm

basically I have objects that are letters at one position and I also have the same number of identical letters at another position. At a certain moment the first set move towards the positions of the identical set through custom movement.

My issue is that I can't seem to make the first set stop moving as they perfectly overlap. I've tried comparing Y's of both and disabling the movement/setting speed to 0 when they are equal, but it does not work. It's like they never hit perfectly on the dot although it's clear they do overlap at one point.

If I just set them to stop moving when they overlap, they stop moving but it's nowhere close to being perfectly overlapped. I could probably just do the positions manually but I know there has to be a simpler way.
B
9
S
2
Posts: 37
Reputation: 729

### » Sat Nov 07, 2015 8:59 pm

They probably never overlap perfectly..

y=200 is not the same as y=199.9999

you could for example compare distance between the two and if it's very small set the movement stopped and set the position to the exact coordinate..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 07, 2015 9:54 pm

LittleStain wrote:They probably never overlap perfectly..

y=200 is not the same as y=199.9999

you could for example compare distance between the two and if it's very small set the movement stopped and set the position to the exact coordinate..

That's what I was left to assume, but I figured it could very well be me making some sort of error.

I googled for a bit and found this tutorial that has a linked capx file https://c2tutorials.wordpress.com/2014/ ... er-object/

I'm sure there's a name for the formula, but in the tut they basically check if a smaller sprite is completely inside of another bigger sprite. If it is then the animation changes, but if even a sliver is outside of the bigger sprite then the animation is not changed. I used the same formula for my issue and it worked!

Anyways, thanks!
B
9
S
2
Posts: 37
Reputation: 729