Version:

This is a **beta** release of our new docs system. Found an **issue**?

Please tell us about it in the**#**ðŸ“–**-newdocs-feedback** channel
on the Phaser Discord

Please tell us about it in the

Find the angle of a segment from (x1, y1) -> (x2, y2).

name | type | description |
---|---|---|

x1 | number |
The x coordinate of the first point. |

y1 | number |
The y coordinate of the first point. |

x2 | number |
The x coordinate of the second point. |

y2 | number |
The y coordinate of the second point. |

The angle in radians.

- number

Since: 3.0.0

Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

Calculates the angle of the vector from the first point to the second point.

name | type | description |
---|---|---|

point1 | Phaser.Types.Math.Vector2Like |
The first point. |

point2 | Phaser.Types.Math.Vector2Like |
The second point. |

The angle in radians.

- number

Since: 3.0.0

Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).

The difference between this method and Phaser.Math.Angle.BetweenPoints is that this assumes the y coordinate travels down the screen.

name | type | description |
---|---|---|

point1 | Phaser.Types.Math.Vector2Like |
The first point. |

point2 | Phaser.Types.Math.Vector2Like |
The second point. |

The angle in radians.

- number

Since: 3.0.0

Find the angle of a segment from (x1, y1) -> (x2, y2).

The difference between this method and Phaser.Math.Angle.Between is that this assumes the y coordinate travels down the screen.

name | type | description |
---|---|---|

x1 | number |
The x coordinate of the first point. |

y1 | number |
The y coordinate of the first point. |

x2 | number |
The x coordinate of the second point. |

y2 | number |
The y coordinate of the second point. |

The angle in radians.

- number

Since: 3.0.0

Takes an angle in Phasers default clockwise format and converts it so that 0 is North, 90 is West, 180 is South and 270 is East, therefore running counter-clockwise instead of clockwise.

You can pass in the angle from a Game Object using:

```
var converted = CounterClockwise(gameobject.rotation);
```

All values for this function are in radians.

name | type | description |
---|---|---|

angle | number |
The angle to convert, in radians. |

The converted angle, in radians.

- number

Since: 3.16.0

Normalize an angle to the [0, 2pi] range.

name | type | description |
---|---|---|

angle | number |
The angle to normalize, in radians. |

The normalized angle, in radians.

- number

Since: 3.0.0

Returns a random angle in the range [-pi, pi].

The angle, in radians.

- number

Since: 3.23.0

Returns a random angle in the range [-180, 180].

The angle, in degrees.

- number

Since: 3.23.0

Reverse the given angle.

name | type | description |
---|---|---|

angle | number |
The angle to reverse, in radians. |

The reversed angle, in radians.

- number

Since: 3.0.0

Rotates `currentAngle`

towards `targetAngle`

, taking the shortest rotation distance. The `lerp`

argument is the amount to rotate by in this call.

name | type | arguments | Default | description |
---|---|---|---|---|

currentAngle | number |
The current angle, in radians. |
||

targetAngle | number |
The target angle to rotate to, in radians. |
||

lerp | number | <optional> | 0.05 |
The lerp value to add to the current angle. |

The adjusted angle.

- number

Since: 3.0.0

Gets the shortest angle between `angle1`

and `angle2`

.

Both angles must be in the range -180 to 180, which is the same clamped
range that `sprite.angle`

uses, so you can pass in two sprite angles to
this method and get the shortest angle back between the two of them.

The angle returned will be in the same range. If the returned angle is greater than 0 then it's a counter-clockwise rotation, if < 0 then it's a clockwise rotation.

name | type | description |
---|---|---|

angle1 | number |
The first angle in the range -180 to 180. |

angle2 | number |
The second angle in the range -180 to 180. |

The shortest angle, in degrees. If greater than zero it's a counter-clockwise rotation.

- number

Since: 3.0.0

Wrap an angle.

Wraps the angle to a value in the range of -PI to PI.

name | type | description |
---|---|---|

angle | number |
The angle to wrap, in radians. |

The wrapped angle, in radians.

- number

Since: 3.0.0

Wrap an angle in degrees.

Wraps the angle to a value in the range of -180 to 180.

name | type | description |
---|---|---|

angle | number |
The angle to wrap, in degrees. |

The wrapped angle, in degrees.

- number

Since: 3.0.0