Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was using box2d for the movement of the body. When I apply gravity (0,0) the bullet continuously move but when I change gravity to the earth the behavior was changed. I also try to apply continuous force to the bullet body but the behavior was not so good. So please provide any suggestion to continuously move bullet body in earth gravity.

currentVelocity = bulletBody.getLinearVelocity();
if (currentVelocity.len() < speed|| currentVelocity.len() > speed + 0.25f) {
    velocityChange = Math.abs(speed - currentVelocity.len());
    currentVelocity.set(currentVelocity.x* velocityChange, currentVelocity.y*velocityChange);
    bulletBody.applyLinearImpulse(currentVelocity,bulletBody.getWorldCenter());
}

I apply above code for the continuous velocity of the body. And also I did not able to find any setGravityScale method in the library.

share|improve this question
    
Need to work on your accept rate Siddharth. –  Byte56 May 19 '12 at 15:31

2 Answers 2

Bullets are subject to gravity as well, they just usually move so fast that it doesn't matter. Are you trying to make something like a rocket that moves quite slowly but steadily across the screen?

You could go around the problem by continuously applying force equal and opposite to the gravity.

share|improve this answer
    
Yes I was making somewhat like rocket in my game. I apply continuous force equal and opposite gravity but that does not work for me and direction of the bullet was change. –  Siddharth May 19 '12 at 9:44
1  
After soom googleing it seems setting to body type to kinematic disables gravity for that body: body.type = b2_kinematicBody; Another option is setting the gravity scale for that body to zero: body->SetGravityScale( 0 ) –  Roy T. May 19 '12 at 11:28
up vote 0 down vote accepted

Update your andengine library for the gravity of the body.By implementing body.setGravityScale(0) method in the library the body does not feel any gravity from the physics world.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.