问题
Good whatever time of day! I have some sprite:
A
point has coordinates Actor.x; Actor.y
.
AB length = 96
BC length = 86
AC length = 42
All calculations are approximate, I made it with help the ruler in Photoshop.
Sprite always towards mouse, angle (in radians) stores in Actor.direction
variable. I draw sprite with scale 0.3
.
All bullets toward mouse (that is Bullet.direction == Actor.direction
). I need to create bullets in the B
point. How I can calculate coordinates of the B
point with any angle?
UPD
If I will create bullets in the coordinates:
x = Actor.x + 96 * math.cos(Actor.direction) * 0.3
y = Actor.y + 96 * math.sin(Actor.direction) * 0.3
I get it:
Excuse my bad English! It isn't my native language. Thank you in advance!
回答1:
Let
cs = math.cos(Actor.direction)
sn = math.sin(Actor.direction)
point B will be shifted from A by
dx = - 42 * sn + 86 * cs
dy = 42 * cs + 86 * sn
Perhaps you will need to change signs before both 42s
(I did not account for scale)
来源:https://stackoverflow.com/questions/44330819/how-to-calculate-coordinates-of-the-gunpoint