Game Development Community

Collision poly doesn't follow flip settings

by Adam Johnston · in Torque Game Builder · 02/23/2006 (3:48 pm) · 4 replies

Hi there
I realized that the collision poly doesn't follow
the flip settings. This is a problem because I have sprites
that aren't centered and the polly is invalid whenever I flip
this sprites, there is quick fix for this?

Thanxs

#1
02/24/2006 (8:16 am)
Hi Adam,

I had the same problem with custom polygons and just worked around it a few minutes ago. My solution was to write a routine to generate a flipped polygon when flipping the sprite. At first it didn't work consistently. Then I decided to make sure the polygon winding stays the same in the flipped polygon, and that made it work. This makes use of two custom fields in my objects. %obj.polyCount and %obj.poly contain the original poly count and the original unmodified collision polygon.

function t2dSceneObject::FlipAndFixPoly(%this, %flip)
{
  %this.SetFlip(%flip);

  if (%this.polyCount)
  {
    %fx = GetWord(%flip, 0);
    %fy = GetWord(%flip, 1);

    if (%fx || %fy)
    {
      %newpoly = "";
      %poly = %this.poly;

      if (%fx != %fy)
      {
        for (%i=%this.polyCount-1;%i>=0;%i--)
        {
          %px = GetWord(%poly, %i * 2);
          %py = GetWord(%poly, %i * 2 + 1);
          if (%fx) %px = -%px;
          if (%fy) %py = -%py;

          %newpoly = %newpoly @ %px SPC %py SPC "";
        }
      }
      else
      {
        for (%i=0;%i<%this.polyCount;%i++)
        {
          %px = GetWord(%poly, %i * 2);
          %py = GetWord(%poly, %i * 2 + 1);
          if (%fx) %px = -%px;
          if (%fy) %py = -%py;

          %newpoly = %newpoly @ %px SPC %py SPC "";
        }
      }
    }
    else
      %newpoly = %this.poly;

    %this.SetCollisionPolyCustom(%this.polyCount, %newpoly);
  }
}
#2
02/24/2006 (8:41 am)
Wwow @Scott thank you
I'll check this definetively.

[EDIT] I was happy until I realized that I need to flip
attached objects that flips when their owner flips...
in this case maybe a general "out the box" solution is required
I've posted a sugestion to GG...
#3
04/13/2006 (4:06 pm)
Hi Adam,

Adam, all you need is a variable for direction, since the direction of your sprite is dynamic most likely based on input. When it goes the other way, change the variable. And just have an animation state change that flips either all mounted objects, or all visible mounted objects each time. There's no since flipping stuff that isn't visible. For me I mount other animations with different collision polys so I only flip when I switch the animation.

Steve
#4
04/14/2006 (4:21 pm)
@Scott,

That's an interesting discovery that the polygon's winding interfere with the collision algorithm. I'm having some problems with collision, so I wonder, should the polygon winding be CW or CCW ?