Difference between revisions of "How to point a sprite at a target"
Jump to navigation
Jump to search
Line 15: | Line 15: | ||
yield | yield | ||
end while</ms> | end while</ms> | ||
+ | |||
+ | [[File:HowToPointScreenshot.png]] | ||
[[Category:Mini Micro]] | [[Category:Mini Micro]] | ||
[[Category:How To]] | [[Category:How To]] |
Revision as of 16:34, 6 March 2020
To point a sprite at a target, use the atan function to calculate the angle in radians, then multiply by 180/pi to convert to degrees, and assign the result to the sprite's .rotation property.
See also How to move a sprite towards a target.
Example
clear
sp = new Sprite
sp.image = file.loadImage("/sys/pics/arrows/arrow2.png")
sp.x = 480
sp.y = 320
display(4).sprites.push sp
while true // (press Control-C to exit)
sp.rotation = atan(mouse.y - sp.y, mouse.x - sp.x) * 180/pi
yield
end while