0
votes

i'm writing an arcade game (like we need more of those right?) that uses box2d and cocos2d (ios). i'm trying to make a bird that you view from the top. there is no gravity in the world (the projection of the gravity vector on my world is the zero vector). i'd like to make the bird sway when you move it from left to right. for the purpose of this question, imagine the bird to be a circle for the head, a rectangle for the body, and three triangles for the wings and tail. how would i make sure it sways when the user interacts. i dont want the user to be able to rotate the bird. one of the things i was considering was to put two opposing strong forces on the head and tail. basically two forces that pull the bird apart. i'm just worried that might give weird side effects. anyone have experience with this sort of interaction?

1

1 Answers

1
votes

I guess by "sway" you mean rotation. I also assume that your bird's body uses multiple fixtures for head, tail and wings instead of them being separate bodies (in which case I'd have to ask "why?").

Given that, just set the body's rotation directly or if you want the rotation to happen over time set the angularVelocity of the body.

With angularDamping you can get it to slow down after a bit, but in any case you'll want to have a check in place that ensures that rotation does not go past a certain point (ie 25 degrees).