2013-03-10 90 views
0

的角度拍攝的射彈我需要設置在運動拋射這樣做(Box2D的):創建矢量在炮

projectileBody-> SetLinearVelocity(b2Vec2(shootVector.x,shootVector.y));

我知道角度(這是大炮的旋轉角度),我確定創建shootVector給定角度很簡單,但我無法弄清楚。我知道tan(angle) = y/x.

CGPoint shootVector = (???, ???); 

回答

0

假設大炮的角度是從x軸:

CGPoint shootVector; 
shootVector.x = velocity * cos(angle); 
shootVector.y = velocity * sin(angle);