How to calculate coordinates of the gunpoint

2019-09-08 03:35发布

Good whatever time of day! I have some sprite:

enter image description here

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:

enter image description here

Excuse my bad English! It isn't my native language. Thank you in advance!

1条回答
▲ chillily
2楼-- · 2019-09-08 03:55

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)

查看更多
登录 后发表回答