CreateRegularPolygon(int, float, float, PhysicsTransform)
Creates a regular polygon, one with every side the same length and every angle the same, from a number of sides and the distance from its center to each vertex. Before the transform is applied, the polygon is centered on the origin with one edge lying flat along the bottom, so a triangle points up and a four-sided polygon is an axis-aligned square. Use it for an equilateral triangle, a hexagon or any other evenly shaped polygon, rather than calculating each vertex yourself and creating the polygon from them.
阅读时间2 分钟最后更新于 20 小时前
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
public static PolygonGeometry CreateRegularPolygon(int sides, float size, float radius, PhysicsTransform transform)
Parameters
The number of sides, which is also the number of vertices, from 3 to PhysicsConstants.MaxPolygonVertices.
The distance from the center of the polygon to each vertex. Must be finite and large enough to keep every vertex.
The radius that rounds the corners of the polygon. Zero gives sharp corners. Must be finite and zero or greater.
The position and rotation applied to the polygon, which moves its center away from the origin and turns it.
Returns
Type | Description |
|---|---|
| PolygonGeometry | The created polygon, with the requested number of vertices. |
Remarks
The size and the transform position are in the same local space and length units as the vertices of any other polygon. The size is the same in every direction, so for a rectangle with a different width and height, use PolygonGeometry.CreateBox instead.
A polygon keeps a vertex only when it lies further than PhysicsWorld.minPolygonCollinearDistance from the line between its two neighbors. The more sides the polygon has, the closer each vertex lies to that line, so the smallest size allowed grows with the number of sides. A size at or below that smallest size throws, rather than returning a polygon with fewer vertices than requested.