Fuze Arena Logo
  • Forum
  • Creations
    Catalogue Showcase
  • Help

atan2()

Purpose

Returns the arctangent between the point specified and the origin.

Description

Unlike ATAN, atan2 requires two values. It returns the angle between the origin and the point specified.

Syntax

angle = atan2( x, y )

Arguments

x The number of horizontal pixels from the origin (0,0)

y The number of vertical pixels from the origin (0,0)

angle The angle between the origin and the specified point

Example

radians( true )
image = loadImage( "Untied Games/Enemy small top C", false )
ship = createSprite()
setSpriteImage( ship, image )
lastpos = { gWidth() / 2, gHeight() / 2 }
setSpriteLocation( ship, lastpos )
setSpriteScale( ship, { 4, 4 } )
loop
    clear()
    c = controls( 0 )
    printAt( 0, 0, "Use left control stick to control sprite" )
    setSpriteSpeed( ship, { 480 * c.lx, -480 * c.ly } )
    curpos = getSpriteLocation( ship )
    if curpos != lastpos then
        setSpriteRotation( ship, -pi / 2 + atan2( curpos.y - lastpos.y, curpos.x - lastpos.x ) )
        lastpos = curpos
    endIf
    updateSprites()
    drawSprites()
    update()
repeat

Associated Commands

acos(), asin(), atan(), pi(), radians(), sin(), sinCos(), tan()

logo

©2019 FUZE Technologies Ltd. FUZE is a registered trademark of FUZE Technologies Ltd. All rights reserved.

Useful links

  • Fuze Main Site
  • Fuze Arena on Twitter
  • Fuze Arena on Youtube
  • Download Buyer

Contact Information

  • FUZE Technologies Ltd
    15 Clearfields Farm
    Wotton Underwood
    Aylesbury, Buckinghamshire
    ​England, HP18 0RS

  • +44 (0) 1844 239 432

  • contact@fuze.co.uk

© Copyright FUZE Technologies Ltd. All rights reserved.