Hello Guest

Author Topic: Collider.Angle  (Read 2217 times)

0 Members and 1 Guest are viewing this topic.

Fruckert

  • Member
  • Posts: 60
  • Total Square
    • View Profile
Collider.Angle
« on: October 22, 2014, 04:15:51 PM »
It'd be really cool if the colliders had the ability to rotate, especially considering that Polygons are now in.
Right now I'm trying to do something a little like Nuclear Throne, but melee based, and I'm finding it surprisingly hard to figure out tight hitboxes.

I believe I have some old physics engine code that might help. I had OBBs, Circles, and Polygons, and I'm pretty sure the collision detection code worked. The collision resolution, on the other hand...
ed: Sorry, I was mistaken. I only have Circle vs. Circle and Circle vs. Polygon code :|
Guess I deleted the others when the impulse resolution didn't work.

Honestly, I'd be perfectly okay if it was just Polygons that have angles. PixelCollider sounds like implementing Angles would be nightmarish, neither Circles or Points need them, and for Boxes you can just create a box shaped Polygon.
« Last Edit: October 22, 2014, 05:08:16 PM by Fruckert »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Collider.Angle
« Reply #1 on: October 22, 2014, 06:31:17 PM »
In the dev branch you might find some new Polygon stuff like .Scale and .Rotate, here's an example of how I'm using it to manipulate a polygon collider:

Code: [Select]
            if (Collider != null) {
                var polyCollider = Collider as PolygonCollider;

                var polygon = new Polygon(basePolygon);
                polygon.Rotate(image.Angle, Collider.OriginX, Collider.OriginY);
                polygon.Scale(image.ScaleX, image.ScaleY, Collider.OriginX, Collider.OriginY);
                polyCollider.Polygon = polygon;
            }

basePolygon is a Polygon that is a copy of the original polygon used in the collider.  The logic is that I keep a copy of the original polygon that the collider has when it's created, and then I copy that into a new polygon that gets scaled and rotated based on the Entity's image, then the collider's polygon is set to that.

Not the most elegant solution right now, I can probably add an angle and scale field into the PolygonCollider as well.

Fruckert

  • Member
  • Posts: 60
  • Total Square
    • View Profile
Re: Collider.Angle
« Reply #2 on: October 23, 2014, 11:42:36 AM »
I don't see the changes in yet, but I'm looking forward to them.

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Collider.Angle
« Reply #3 on: October 23, 2014, 04:47:26 PM »
Oh I am so cool that I forgot to push the changes yahoo