Rectangle Rotate Function

Hi,

Just wondering why there isn’t a rotate function for rectangles e.g. Phaser.Geom.Triangle.Rotate. I’m trying to emulate this steering tutorial I found, but I can’t seem to find a rotate for rectangles.

I’m not the best at math, so bare with me.

I might be missing the point of the question but… Arcade physics doesn’t have rotation. Matter JS (and I believe Impact) do. You can set .rotation (radians), or .angle (degrees)

Apart from what quasipickle said, Rectangle shapes are axis-aligned, which means they can’t be rotated. How you’d rotate a rectangle depends on how your code uses it.

As a side note, I don’t think Impact can rotate bodies. Only MatterJS supports complex collision.

Hi,

I wasn’t thinking of using a rectangle for collisions/overlays per se, but I guess thinking about your replies that’s what it is. I was just thinking of a rectangle that is projected in front of my enemy ship and can rotate along with it. Kind of like the example below, but with a rectangle.

I’m trying to model some ideas from http://opensteer.sourceforge.net/ where each ship has a long rectangular box that helps it steer away from obstacles and other ships.

I’ll check into Impact and Matter JS, but I’ve been working on this game for a long time and would like to release it.

Thanks for the help,
DaSoup

Think I’ll try two triangles and see how it works.

Some other ideas if two triangles does not work for you and you don’t want to use matter/impact.

1: Perhaps create a rectangle using the factory? This will make a gameobject that is like the geom rectangle but can be rotated. this.add.rectangle(…) to create it and then move/rotate it with relation to the ship gameobject and set visible false if the rectangle is not meant to be seen.

2: You can get the points of a Phaser.Geom.Rectangle (or change to Phaser.Geom.Polygon) and then loop through them to update their position using Phaser.Math.RotateAround(…) again using the ship gameobject as a point to rotate around/with.

1 Like

I’ll look into those. Thanks. Seems like every door I open in Phaser leads to like five more.

I appreciate the help.