# Y positions match but dont triger an action (SOLVED)

hi all,
pl object is moving up and down and when y position matches with test object it should add 1 to variable but it doesn’t. What am I doing wrong ?

Because you are using forces, the Y position will be a decimal value. Decimals have a long tail of numbers, and the chances of 2 being the same are very, very unlikely.

A solution would be to round or truncate both Y values and then test if they are the same.

Or to take the difference between the 2 y positions and check if it’s below a threshold - for example `abs(test.CenterY() - pl.CenterY()) <1`

1 Like

On top of what MrMen wrote
I remember doing something similar thing and it turns out sometimes it moves to fast too register
So frame where each object should be at same Y position said frame is just skipped

Ow now i know
I was trying to change animation of player based on mouse position
And i went with
Angle of mouse to player is equal to 135 or 45 for example (when mouse was below player)
Meaning at this one frame it would need to register that mouse is at this position but i moved mouse so fast it did not have chance to register

Solution was to check range
like instead of checking if angle is equal to 135 or 45 checking range of
FOR EXAMPLE angle is lower than 135 and higher than 45
I was checking if mouse is in that area range from player

I think that would be also solution for you
Where you need to check some range and not just one single value

thanks,
I have tried that and when they match it does trigger an action
but it works only if I carefully match y positions
If I move pl object up and down they don’t match (click)

solved,
something like this ?

1 Like

Exactly yet i think 10 would be enough
But idk what are your needs so may be you do need 100

Bottom line you want to get away with as lowest value as possible
Do some test and check what is the lowest which you can use

Of course you can stay with 100 if it works perfectly fine with you
Then do not change anything and just enjoy

Also i would add trigger once to it
If you won’t then each frame object is in that range it will constantly add+1
If you add trigger once it will add +1 and then wait for object o leave that range and then add another if it comes back to that range

1 Like