set velocity at angle
Problem it solves
You know the direction and speed you want a sprite to move in, but Arcade's built-in blocks only let you set vx and vy separately.
What this block does
Sets a sprite's velocity so it moves at the given speed in the given direction (an angle in radians).
The block
Block ID: spriteutilextsetspeedanglefrom
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
| target | Sprite | mySprite | The sprite to move |
| angleInRadians | number | — | The direction of travel |
| speed | number | — | How fast to move, in pixels per second |
Example
let mySprite = sprites.create(img`.`, SpriteKind.Player) let myEnemy = sprites.create(img`.`, SpriteKind.Enemy) spriteutils.setVelocityAtAngle(mySprite, spriteutils.angleFrom(mySprite, myEnemy), 100)
Add the extension
Add github:jwunderl/arcade-sprite-util to your project, or open: Import arcade-sprite-util.