Skip to content

Commit

Permalink
feat: Implement "point towards random direction"
Browse files Browse the repository at this point in the history
We subtract 180 even though the value will be clamped, for clarity. We round so that
using the "direction" getter will yield a sensible result. Note that this
implements 'point towards random direction', not 'point towards random
position' -- they have slightly different behaviours.
  • Loading branch information
joker314 committed Nov 11, 2018
1 parent 3050f49 commit 306996e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/blocks/scratch3_motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class Scratch3MotionBlocks {
if (args.TOWARDS === '_mouse_') {
targetX = util.ioQuery('mouse', 'getScratchX');
targetY = util.ioQuery('mouse', 'getScratchY');
} else if (args.TOWARDS === '_random_') {
util.target.setDirection(Math.round(Math.random() * 360) - 180);
return;
} else {
const pointTarget = this.runtime.getSpriteTargetByName(args.TOWARDS);
if (!pointTarget) return;
Expand Down

0 comments on commit 306996e

Please sign in to comment.