How to Get Consistent Sprite Tracking Speeds on Scratch

by Witheredboi in Circuits > Software

226 Views, 0 Favorites, 0 Comments

How to Get Consistent Sprite Tracking Speeds on Scratch

Screenshot 2021-03-23 at 9.45.13 AM.png

This mostly applies to things trying to kill you in any game you make.

I struggled with this for a while. What I mean by consistent tracking speed is making a sprite glide at the same speed towards a target, no matter the distance.

This, of course, uses the "glide to" block, but it took a little while to get the code right to get the desired effect, since it takes some manipulation to get right.

Supplies

Demonstration

And a scratch account.

The example obviously isn't needed, it just shows what I mean.

Surprisingly Simple

Screenshot 2021-03-23 at 9.40.38 AM.png

This is actually a shockingly simple piece of code. It takes 3 blocks to do: one that identifies the target (glide to Warden), one that sets a level pixels-per-second speed (distance to Warden), and one to alter the speed (divided by 300). The higher the divisor, the faster the sprite moves (as seen when attacking the player after recieving a sculk signal).