How to point a sprite at a target

From MiniScript Wiki
Revision as of 13:57, 4 March 2020 by JoeStrout (talk | contribs) (Created page with "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 spr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

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