Collisions

edited November 2014 in Help request
My brief experience with 2d game programming is that you mark areas that are collidable with polygons. You can also set up entire objects as collidable, like a player. I've seen it done different ways, but I don't know how it's done in orx. sausage showed me how to set the polygons in inkscape and export a mesh for orx (also using tiled, I think). That's pretty cool. But what do I do with that? How do I turn on collision? Knolan showed me how to set a callback for it. Remember, I don't know squat about collisions for orx yet. Notta! Nuttin! Let me know if I'm making any sense here. I'm not good at explaining...

Comments

  • edited November 2014
    You don't really turn it on or off*, basically the orxOBJECT can have a Body property, if it is set it will "collide." All the objects that do not have a Body property set will not collide.

    If the Body have any BodyPart that have the Solid property set to truth, the physic impact will occour, otherwise only an event will be sent.

    The BodyPart can be one of three types Box, Sphere or Mesh (or Polygon). It is the part that hold the collider form (in other words, the points that define where it will collide).

    * In a way you do, you need to init the physics module and enable the simulation:

    orxPhysics_Init();
    orxPhysics_EnableSimulation(orxTRUE);
  • edited November 2014
    Ha! Ok, now I'm starting to understand. I'm going to try what you've said and wee what happens. Thanks for your input!
  • edited November 2014
    OK, I got my object to push a box around. That's cute. I'll have to play with it some more. For anyone else interested here's some more detail. This is just for one object:
    ;========== helmet object ================
    [helmetGraphic]
    Texture = helmet.png
    
    [helmetPart]
    Type        = box
    Restitution = 0.0
    Friction    = 1.0
    SelfFlags   = 0x0001; <= This defines our collision flags
    CheckMask   = 0xFFFF; <= This defines the collision mask that will be testing on other objects
    Solid       = true; <= If it's not solid, we'll still have the collision info with the callback, but no physical collision will happen
    Density     = 1.0; <= This will be used only by dynamic bodies (boxes) and not static ones (walls)
    ; As we don't specify TopLeft and BottomRight value, the part will use the full size of the body/object that's using it
    
    [helmetBody]
    PartList    = helmetPart
    Dynamic     = true; <= We use the same physical body than ground, except we are dynamic and not static
    
    [helmetObject]
    Group        = Playground
    Graphic      = helmetGraphic
    Position     = (200.0, 0.0, 0.0)~(250,0. 20,0, 0.0)
    Pivot        = top left
    Scale        = (0.15,0.15,0.0)
    Color        = (255, 0, 0)
    ;Alpha       = 0.0
    Rotation     = 90
    Body         = helmetBody
    
  • edited November 2014
    As a small side note: you can now use literals for SelfFlags and CheckMask. Orx will then associate flags to them and complain if you go over the limit of 16 (which is defined by Box2D).
    Example:
    [helmetPart]
    SelfFlags = helmet
    CheckMask = player # ground
    
    [groundPart]
    SelfFlags = ground
    CheckMask = helmet # player
    
    [playerPart]
    SelfFlags = player
    CheckMask = player # ground # helmet
    
  • edited November 2014
    Thanks for more info. I'm still fuzzy on selfflags and checkmask. I assume the mask is for the flags but don't know what they do really.
  • edited November 2014
    The best is probably to have a look at Box2D's doc (it's fairly standard across all the physics engine solutions): http://www.box2d.org/manual.html#_Toc258082972
    Section 6.2, subcategory "Filtering".

    categoryBits = SelfFlags
    maskBits = CheckMask
  • edited November 2014
    Thank you, I'll look at it in a bit.
Sign In or Register to comment.