I have a new concept to test it out, but I was wondering if you could look over this and tell me why its wrong or bad. I noticed if the length of an object is beyond the width of the 2nd object its point is thenout of the area but still overlapsresulting in the software thinking the collision didn't happen.
objA and objB are just pygame.Rects.
- Code: Select all
def collide_obj(objA, objB = None, objList = None):
if objB is not None:
if objA.w > objB.w:
objAw = objB.w
print "in w"
if objA.h > objB.h:
objAh = objB.h
print "in h"
if objA.top <= objB.top + objB.h and objA.top >= \
objB.top and objA.left <= objB.left + objB.w and \
objA.left >= objB.left\
objA.top + objAh >= objB.top and objA.top + objAh <= objB.top + objB.h\
and objA.left + objAw > objB.left and objA.left + objAw <= \
objB.left + objB.h \
some of the it tests was just to see if it could work. Imagine this code without those if tests if you want to get the gist of what this collision detection is all about. Thanks.
The first few if test was a non working fix that acknowledgedd that some widths or lengths was longer so the point was outside of the region detecting for collisions.