开发者

Converting rotation degrees to Box2D impulse

开发者 https://www.devze.com 2023-01-29 07:18 出处:网络
Many apologi开发者_运维技巧es if this has been answered before but I wasn\'t able to quite find what I was looking for.

Many apologi开发者_运维技巧es if this has been answered before but I wasn't able to quite find what I was looking for.

I have a Box2D dynamic body that I apply linear impulse to to turn it into a projectile. So when I click anywhere on the screen I want the body to be projected towards the touch location. I'm not concerned about the force yet, just the angle.

I already have my sprite rotating to point to the touch location so I can detect the initial rotation angle but how do I turn this angle, say 45 degrees into a "b2Vec2" value so that I can launch the body at exactly 45 degrees? something like this:

float rotationValue = 45.0f;
b2Vec2 vect = ??????
b2Vec2 PointVector = body->GetPosition();
body->ApplyLinearImpulse(vect, PointVector);

Any clues would be greatly appreciated.

Thanks


sigh - this is why you should pay attention in your Math class :)

Converting angles to vect is super simple:

float angle = 45.0f;
b2Vec2 vect = b2Vec2(cos(angle), sin(angle));
0

精彩评论

暂无评论...
验证码 换一张
取 消