MakeCode Games!

A fan-made community library of MakeCode Arcade games. Visit MakeCode Arcade to make a game!

← Back to extensions

Sprite Utils

A grab-bag of sprite math and rendering helpers for MakeCode Arcade: distances, angles, movement, timers, and simple drawing.

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

set $target velocity at angle $angleInRadians speed $speed block

Parameters

NameTypeDefaultMeaning
targetSpritemySpriteThe sprite to move
angleInRadiansnumberThe direction of travel
speednumberHow 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.