Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Detecting collision direction uncorrect  (Read 1083 times)

0 Members and 1 Guest are viewing this topic.

denis318

  • Newbie
  • *
  • Posts: 7
    • View Profile
Detecting collision direction uncorrect
« on: October 05, 2017, 11:23:17 am »
I have a four FloatRects, that anwser for sprite animation frames collision directions, i initialize it for each frame in Animation.h
ColPointDivide its a integer that equals 10, i use it that the edges do not intersect (up-right,up-left,etc...)
i.e i want to create a FloatRect (Collision box) that little offseting from top to bottom Y points, trying deny edges intersecting
Quote
      *leftRect = FloatRect(
         0,
         R.height / ColPointDivide,
         R.width / 2,
         R.height - R.height / ColPointDivide
      );
      *upRect = FloatRect(R.width / ColPointDivide,
         0,
         R.width - R.width / ColPointDivide,
         R.height / 2);
      *rightRect = FloatRect(R.width / 2, R.height / ColPointDivide, R.width / 2, R.height - R.height / ColPointDivide);
      *downRect = FloatRect(R.width / ColPointDivide, R.height / 2, R.width - R.width / ColPointDivide, R.height / 2);
In code when i want to check collision, i trying this:
(mtv its a SAT mtv, that contains collision depth, like 0,1)
(curColRect its an array vector of FloatRects with size 4, i calling i needed direction, and current animation frame)
Quote
for each (Block bl in m_engine->MapBlocks)
      {
         FloatRect blrect = bl.sprite.getLocalBounds();
         //auto B = bl.sprite.getLocalBounds();
         
         //RectangleShape colupshape(Vector2f(curAnim.Col_up.width,curAnim.Col_up.height));
         //colupshape.setPosition(curAnim.Col_up.left, curAnim.Col_up.top);
      //   m_engine->AddSprite(&colupshape, 0);
         Vector2f mtv;
         if (m_engine->m_math.sat_test(bl.sprite, kidspr, &mtv))
         {
            FloatRect mtvrect(mtv.x, mtv.y, blrect.width-mtv.x, blrect.height-mtv.y);
      //      coutMTV(mtv);
            if (!passed[ColPoint::up])
            {

               if (mtvrect.intersects(curColRect[ColPoint::up].at(curf)))
               {
                  setPos(
                     Vector2f(
                        kidentity->GetX(), bl.sprite.getPosition().y - kidentity->anim.getSprite()->getOrigin().y
                     ));
                  colUP = true;
                  passed[ColPoint::up] = true;
                  
               }
            }

// and that for each direction...
I also setting false all booleans to false above, and its method calling with gameloop some often like drawing, under i setting booleans that wasnt colliding to false
(under code)
(click to show/hide)
(above code)
(click to show/hide)
So, when my sprite with animation collides to a block by up, ALL booleans that anwser for collision (colDOWN,colLEFT,colRIGHT,colUP) are true, but collision was by up point...
I also trying use CurColRect[point][curf].contains(mtv), but this work veery strange, when collision by up, all collision booleans are false, only colLEFT are true, idk why
Please help me, idk what is wrong
I also dont want to use Box2d for its objectives
I use SFML 2.4.2
sat_test method:
(click to show/hide)
« Last Edit: October 05, 2017, 11:27:10 am by denis318 »