I need to know how to use box2d for projectile motion.
initially, projectileTime=0;
then i call the following function for projectile motion. It works pretty good.
But i want to achieve the same thing using box2d. As far as i know Box2d works only with force, it does not encourage placing object directly, So how to use Box2d for projectile movement??
-(void)projectilelaunched:(ccTime)dt
{
projectileTime+=(5*dt);
double vh=v*cos(theta);
x=vh*projectileTime;
double y = x*tan(theta)- 10*((x/vh)*(x/vh))/2;
projectile.position=ccp(projectilePositionBeforeLaunched.x + x,projectilePositionBeforeLaunched.y+y);
}
With box2D, you’d only need to set its initial position and initial velocity (via
applyForce). Box2d will take care of the rest, applying gravity, stopping when hitting other objects etc.