create vector from sprites
Problem it solves
You have an enemy boss that needs to aim and shoot a missile directly at the player, but you don't know the exact angle or distance between them.
What this block does
Creates a vector pointing from the first sprite directly to the second sprite. The magnitude is set to the distance in pixels between them, and the direction is the angle in degrees pointing at the target.
The block
Block ID: vectormath_create_vector_from_sprites
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
| spriteFrom | Sprite | null | The starting sprite where the vector begins. |
| spriteTo | Sprite | null | The target sprite where the vector points. |
Returns
Vector — A Vector object pointing from the source sprite toward the target sprite, with magnitude equal to the distance between them.
Example
let enemy = sprites.create(img`.`, SpriteKind.Enemy) let player = sprites.create(img`.`, SpriteKind.Player) let aim = vectorMath.createVectorFromSprites(enemy, player) let bullet = sprites.createProjectileFromSprite(img`.`, enemy, aim.x, aim.y)
Add the extension
Add github:robo-technical-group/pxt-arcade-vector-math to your project, or open: Import pxt-arcade-vector-math.