# Collison detection trouble. (c++ SDL2)

I have a small trouble with my collsion detection system, ill show it on images. im checking the detection by using that logic with example when moving to the right:

obj.x+obj.w+obj.mov > block.x
obj.x+obj.w+obj.mov < block.x+block.w
and
(
obj.y <= block.y
obj.y+obj.h >= block.y
or
obj.y <= block.y+block.h
obj.y+obj.h >= block.y+block.h
)


when object size and block size are equal, the problem appears

the 3 blocks are detected

1 = is the trouble maker

2 = isnt making much problem, since its on same axis

3 = is working

the 1 block is detected since its within Y + H area of the block (

it happens when the object is sticked with 0 pixel distance.

im using motion based on min(mov,dist) [dist is Y distance between object and block] function and when it tries to move to the right, it gets moved like that

because min(mov,dist) will become negative when getting distance to object 1 instead of 3, making it buggy

im asking if its possible to prevent block 1 (block 2 optionaly) when that situation happens. (or atleast change the logic)

• i have fixed the negative jump, but the logic still needs to be fixed, cause it gets stuck on edges. – terrio no May 29 '17 at 13:08

At a glance, your code is doing what it's supposed to, which is detecting collisions (distance between 2 edges <= 0).

It sounds like you want to detect intersections instead, which is two AABB's overlapping. In which case, change:

and
(
obj.y <= block.y
obj.y+obj.h >= block.y
or
obj.y <= block.y+block.h
obj.y+obj.h >= block.y+block.h
)


To:

and
(
obj.y < block.y
obj.y+obj.h > block.y
or
obj.y < block.y+block.h
obj.y+obj.h > block.y+block.h
)


i have solved it, logic should look like this

     obj.x+obj.w+obj.mov > block.x
obj.x+obj.w+obj.mov < block.x+block.w
and
(
obj.y <= block.y
obj.y+obj.h >= block.y
or
obj.y <= block.y+block.h
obj.y+obj.h >= block.y+block.h
)
and
obj.y != block.y+block.h
and
obj.y+obj.h != block.y