0

How can my sprite will jump and come back to original place?? I am using box2d physics engine in iphone apps. I am using impulse but cant work properly.

Is any one know the logic or code than tell me.

-(void)jump
{
    b2Vec2 pos=ballbody->GetPosition();
 //   float vel=ballbody->GetAngularVelocity();
    double radian=atan2(pos.x+10, pos.y+10);
    float angle=CC_RADIANS_TO_DEGREES(radian);
    NSLog(@"Angle: %f",angle);
     float impulseFactor = 1.0;
   float force=ballbody->GetMass()*10;
    //force/=6.0;
    //b2Vec2 force=b2Vec2(0,50.0f);
  //  float apply=force*JUMP_IMPULSE*impulseFactor;
    ballbody->ApplyLinearImpulse(b2Vec2(angle,force), ballbody->GetWorldCenter());

 //  [self applyLinearImpulse:b2Vec2(0,[self mass]*JUMP_IMPULSE*impulseFactor) point:[self worldCenter]];

}

Thanks

Diken Shah
  • 69
  • 6

1 Answers1

0
  1. please check whether gravity has been set
  2. if not set gravity upon the particular angle you have put the force.
  3. third case is note down that position... get the current position... get angle.... set linear velocity to that angle.... keep on checking the position and as soon as it reaches that position set linear velocity zero..... (this sounds confusing but i didn't understood your problem fully so as much as i did understood i can help only this much)
Umesh Sharma
  • 388
  • 5
  • 23