3
\$\begingroup\$

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
)

detection1

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

detection2

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

detection 3

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)

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

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
)
\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.