Simple gun in cocos2d + box2d

I am new to box2d. Could you help me? I want to make a gun (touch, move, stop, fly the ball). I do the detection and rotation of the gun, but I can not make a splash of the ball. How can I calculate the speed that I need to set on the ball? Many thanks

+2
source share
1 answer

The easiest way is to look at the direction that the gun points when you identify the body, and use GetWorldVector to see how it changes. For example, if a gun points straight up when you create a body, this will be the direction (0,1). Then you can use GetWorldVector at any time to get the current direction of this vector in world coordinates:

body->GetWorldVector( b2Vec2(0,1) ); 
+8
source

Source: https://habr.com/ru/post/1400114/


All Articles