How to calculate coordinates of the gunpoint

送分小仙女□ 提交于 2020-01-17 06:43:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!