Simple gun in cocos2d+box2d game
Asked Answered
E

1

2

I'm newbie in box2d. Can you help me? I want to make gun (touch, move, stopped, ball flew). I make detection and rotation of gun, but I can't make popping of ball. How can I count velocity, which I need to set to the ball? Thank you very much

Erasure answered 6/2, 2012 at 17:12 Comment(2)
What have you tried so far, and what specific part of your task are you having problems with? Please post your code and/or resources.Temperamental
My pump is simple b2body, there are no something unusual.Erasure
B
8

The easiest way is to look at the direction the gun is pointing when you define the body, and use GetWorldVector to see how it has changed. For example if the gun is pointing directly upwards when you create the body, this would be the direction (0,1). Then you can use GetWorldVector at any time to get the current direction of that vector in world coordinates:

body->GetWorldVector( b2Vec2(0,1) );
Blastomere answered 6/2, 2012 at 21:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.