ScratchData LogoScratchData
Back to _nix's profile

Rotate degrees around sprite (remix)

_N_nix•Created January 20, 2023
Rotate degrees around sprite (remix)
8
6
100 views
View on Scratch

Instructions

Move the mouse around to see how the sprite's rotation reflects the distance to your mouse. You can also drag around the pivot (the "+" shape the sprite rotates around), or click the pivot to make it automatically follow your mouse.

Description

Thanks to @hill_walker123 for the original "rotate around" custom block! My remix makes it not animate a full 360 degree circle, so you can make custom animations (e.g. a semicircle arc which slows down towards the end), dynamics (pause and play, reacting to other changes), etc. I didn't really add anything so much as take away the parts I don't personally need. So, full credits still go to @hill_walker123 for the idea and code :D That code (this project too) basically works by keeping the distance between the sprite and the pivot the same, using basic trigonometry blocks to change the angle. Basically, every time you run the block, the code imagines a circle which is centered on the pivot and has one point on the sprite, then asks, "what are the X and Y coordinates of the point 45 degrees further on this circle?" (or some other degree value). Since it's a circle centered on the pivot, the distance for all points on the circle is the same (just the circle's radius!), so you get that important "change direction to pivot but not distance" property! Something to note in my remix is that if the sprite rubs up against the edge of the stage (try moving the pivot), it will get automatically fenced in (that's a long-standing Scratch feature to keep sprites from being unreachable by the mouse). That means the distance to the pivot will actually become smaller, so it'll make a smaller circle around the sprite. The original project avoids this by calculating the distance once and reusing it for the entire animation, but since in this project we WANT to be able to react to the distance changing, there isn't really a good way to avoid it. You can use tricks like making the sprite way bigger then sizing it down after it moves, or switching to a bigger costume and then back after it moves.

Project Details

Project ID791029069
CreatedJanuary 20, 2023
Last ModifiedFebruary 14, 2023
SharedJanuary 20, 2023
Visibilityvisible
CommentsAllowed

Remix Information

Parent ProjectView Parent
Root ProjectView Root