angle from
Problem it solves
You want an enemy to face or move toward the player, but you only have the two sprites' positions, not the direction between them.
What this block does
Returns the angle, in radians, pointing from one sprite, point, or tile location to another. If either is missing, it returns 0.
The block
Block ID: spriteutilextanglebw
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
| a | Sprite / Location / Point | mySprite | Starting point |
| b | Sprite / Location / Point | myEnemy | Target point |
Returns
number — The angle in radians from a to b.
Example
let mySprite = sprites.create(img`.`, SpriteKind.Player) let myEnemy = sprites.create(img`.`, SpriteKind.Enemy) let angle = spriteutils.angleFrom(mySprite, myEnemy) console.log(angle)
Add the extension
Add github:jwunderl/arcade-sprite-util to your project, or open: Import arcade-sprite-util.