# Physics Help

## Recommended Posts

anupgupta    128
hello

we are currently working on an iphone game and using cocos2d and box2D for it.

the game works as when the catapult throws the player at a particular angle above...
the player has animations like sitting, ready to go and flying through air....
currently when the catapult throws the player animation changes correctly but it starts to rotate randomly...
i want to know as to how can i make the player go through the air in a linear fashion facing straight(i have animation for looking straight forward)....but it rotates in a circular fashion after being thrown from the catapult..
also i want it to experience some drag(air resistance) while flying...and the air resistance changing its angle while in the air

any help or advice is appreciated.

the physics i want is similar to this game [url="http://www.miniclip.com/games/catapult/en/"]http://www.miniclip.com/games/catapult/en/[/url]

Thank You

##### Share on other sites
jyk    2094
I believe Box2D has a 'freeze rotation' option; if so, that might solve your first problem.

##### Share on other sites
anupgupta    128
Hidden
hello<br><br>i have successfully made a catapult using Box2d...i have a player sitting on the catapult ...the catapult throws the player in the air.<br>the user playing tries to maintain the player angle through the accelerometer which if he fails the player angle changes due to air resistance and the player rotates in mid air(or thralls) <br><br>here is the code i implemented..<br>1. the code below makes my player move in the air in a parabolic fashion..and after colliding to the ground comes to the halt(for which i applied friction, angluar damping)<br><br>- (void) CorrectPlayerRotation<br>{<br>&nbsp;&nbsp;&nbsp; b2Vec2 _linearVelocity;<br>&nbsp;&nbsp;&nbsp; float32 _velocityAngle = 0;<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; _linearVelocity = gameBodies[BOD_ANIM_PLAYER]-&gt;GetLinearVelocity();<br>&nbsp;&nbsp;&nbsp; _velocityAngle = atan2f(_linearVelocity.y, _linearVelocity.x);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; gameBodies[BOD_ANIM_PLAYER]-&gt;SetTransform(gameBodies[BOD_ANIM_PLAYER]-&gt;GetPosition(), _velocityAngle);<br>}<br><br>i basically want to know as to how do i implement the air resistance thing and also get the player rotating in mid air after he fails to maintain a balanced angle...

##### Link to post
anupgupta    128
hello

i have successfully made a catapult using Box2d...i have a player sitting on the catapult ...the catapult throws the player in the air.
the user playing tries to maintain the player angle through the accelerometer which if he fails the player angle changes due to air resistance and the player rotates in mid air(or stalls)

here is the code i implemented..
1. the code below makes my player move in the air in a parabolic fashion..and after colliding to the ground comes to the halt(for which i applied friction, angluar damping)

- (void) CorrectPlayerRotation
{
b2Vec2 _linearVelocity;
float32 _velocityAngle = 0;

_linearVelocity = gameBodies[BOD_ANIM_PLAYER]->GetLinearVelocity();
_velocityAngle = atan2f(_linearVelocity.y, _linearVelocity.x);

gameBodies[BOD_ANIM_PLAYER]->SetTransform(gameBodies[BOD_ANIM_PLAYER]->GetPosition(), _velocityAngle);
}

i basically want to know as to how do i implement the air resistance thing and also get the player rotating in mid air after he fails to maintain a balanced angle...
P.S: the game and effect is similar to the link [url="http://www.miniclip....es/catapult/en/"]http://www.miniclip....es/catapult/en/[/url]

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account