i need to calculate the x/y of a certain point to know where to create a bullet.
so lets say i know the length of the hand and the length of the gun then i have the angle of the hand and with sin/cos i can get x/y but the gun is not in the same line with the hand its a little bit above so what i get is the bullet is created not where the gun is it is created with the 0 line of the hand.
here is a image to explain my problem:
when angle is 0 i can just say create the bullet with some pixels above the zero line but when angle changes how can i calculate exact x/y of the barrel of the gun?
You can precalulate the distance GunRadius of the gun output from the rotating point. GunRadius = Sqrt(GunX * GunX + GunY * GunY)
GunX and GunY are the coordinates of the gun output with 0 hand angle.
Then you can precalulate the GunAngle between 0 hand angle and the gun output. GunAngle = ATan(GunY / GunX)
The you can calculate the gun output coordinates for every hand angle. x = GunRadius * Cos(HandAngle + GunAngle)
y = GunRadius * Sin(HandAngle + GunAngle)
1- Bullet spawn point. Klaus pointed it at his first sketch. You can find it after you found hand angle, using by GunAngle and Gunradius values. You'll add handangle and gunangle to find bullet spawn point.
2- Bullet spawn angle. It is same as hand angle.
Sub calcBulletXY(GunX As Float, GunY As Float, Angle As Float) As Point
Dim GunRadius,x,y,GunAngle As Float
GunRadius = Sqrt(GunX * GunX + GunY * GunY)
'
GunAngle = ATan(GunY / GunX)
x = GunRadius * Cos(Angle + GunAngle)
y = GunRadius * Sin(Angle + GunAngle)
Dim p As Point
p.Initialize(x,y)
Return p
End Sub