Node Script

Atan2

Downloads: 49
Download
Ads Support FTD

Description

Atan 2 Calculates the angle from a Vector2f

//
// --------------------------------------------------------
// Atan2Node – Calculates the angle from a Vector2f
// Written by @Fusedthreed – https://FusedThreeD.com
// --------------------------------------------------------
//

@customNode()
export class Atan2Node extends BasicScriptNode {
  @input('Vector2f')
  vector2: APJS.Vector2f;

  @input('bool')
  degrees: boolean = false;

  @output('float')
  angle: number;

  execute() {
    if (!this.vector2) {
      this.angle = 0;
      return;
    }

    const { x, y } = this.vector2;

    const angleRad = Math.atan2(y, x);

    this.angle = this.degrees
      ? angleRad * (180 / Math.PI)
      : angleRad;
  }
}
Ads Support FTD