CollisionMap#collides_with - need help

Discussion
2005-06-06
2013-04-09
  • Hi,

    What does the return value of CollisionMap represent?  I've created some images that I'm moving around the screen, making then collide at various points, and I can't seem to figure out what the HELL the output means!  Is it the position of the collision map given as argument compared to the 'self' collision map?

    I've got an image arranged as follows (note, 0 means 'white',  X means 'black')

    X0X
    000
    XXX

    I make 2 collision maps, and make them collide using collisionmap1.collides_with([0, 0], collisionmap2, [-2, 2]) so that they look like this: (stupid variable size fonts!  Sourceforge!  Fix it!)

      X0X
      000    (collision map 1)
    X0XXX
    000
    XXX  (collision map 2)

    (you'll have to copy-paste into a fixed-font area, like notepad on Windoze, to make it work correctly - unless your browser displays by default in fixed-font)

    I get the following output as a result from the return value (retval.inspect)

    [-2, 0]

    When I do collisionmap1.collides_with([0, 0], collisionmap2, [-1, 2]), I still get the same answer!  What's going on?

    What does that mean for goodness' sake?!  Point of collision relative to collision map 1?  Or what?  I'm so confused.

    Thanks

     
    • The coordinates, if I remember correctly (because this code is in an external library, not made by us) are the first point where the two collision maps collide. The remarks in the code say:

      /* x and y are given in the coordinates of mask a, and are untouched if the is no overlap */

      x and y are returned, so yes, it is the point of collision relative to map a (or 1)

       
    • OK boys and girl (there can't be more than one here, can there?!?!) listen up, I'll only repeat this ONCE.

      bog = map1.collides_with(co1, map2, co2)

      bog is the point relative to map1 where collision occurs, as detected in top-to-bottom left-to-right searching for collisions.

      UNLESS co2[0] < co1[1]

      In which case the return value makes absolutely no sense to me whatsoever.

      I've just spend 45 minutes relearning my bloody vector maths to work out the following little source for working out the first detected point of collision relative to map1 IN ALL CASES:

      iscol = nil
      if(co2[0] < co1[0])
          iscol = map2.collides_with(co2, map1, co1)
          if(iscol)
              iscol[0] = iscol[0] + co2[0] - co1[0]
              iscol[1] = iscol[1] + co2[1] - co1[1]
              end
      else
          iscol = map1.collides_with(co1, map2, co2)
      end

      Note all the maths related to moving the origin of a point from one place to another (in this case moving the origin of the point of collision from co2 to co1 if map2.collides_with(..) had to be called instead of map1.collides_with(..) )

      I don't know why this works, it just does - its that Elf bloke's fault for not including PROPER DOCUMENTATION.

      Gah, glad that's over!

       
    • NOTE I made a mistake above

      The line that reads:

      UNLESS co2[0] < co1[1]

      Should read

      UNLESS co2[0] < co1[0]

       
    • By 'Elf bloke', I meant the bitmask guy - what's his name?  Didn't want any RUDL developers thinking the comment was about them.

       
      • Ulf Ekstrom :)