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 am new to Box2D, I have set gravity to 10. How to make an object fly in space even though the gravity is 10. What are the properties I need to set to make object fly? Is there any different approach?

share|improve this question
3  
Use a slingshot: lapitapi.com/… –  Petteri Hietavirta Mar 16 '11 at 16:40
add comment

2 Answers 2

up vote 4 down vote accepted

It sounds like you essentially want to have specific objects ignore gravity, is that correct? Since gravity is a property of the world object, it looks like the way to do this is to either

  1. Disable gravity entirely, and then manually apply gravity to every object you want to have it (ignoring the objects you don't want to be affected by gravity), or
  2. Apply a force that counteracts the force of gravity every frame to the objects you want to appear to be unaffected by gravity.

You also may be able to use a b2_kinematicBody instead of b2_dynamicBody if you don't need your "flying" objects to respond to any forces whatsoever. This may or may not be appropriate for your needs.

share|improve this answer
    
I don't want to ignore the gravity... I will try by applying force... –  Chandan Shetty SP Mar 16 '11 at 16:24
1  
If you don't want to ignore gravity entirely, can you be more specific about what you mean by "fly?" Suffer a reducing effect from gravity? –  Josh Petrie Mar 16 '11 at 17:51
    
Yup it worked(By applying force to bird)... How to make bird to moving randomly in the screen. Do i need to apply force randomly and continuously? –  Chandan Shetty SP Mar 16 '11 at 18:11
    
You should probably make a few states for bird flight patterns, and randomly switch between different modes of flight patterns. Don't just use completely random forces and directions or that will not look like a bird at all. –  AttackingHobo Mar 16 '11 at 22:25
    
Can you explain little bit... How to make a bird to move in the described flight patterns... –  Chandan Shetty SP Mar 17 '11 at 8:24
add comment

In general, the best way is to make your object dynamic and add a force to it in every frame, to the left or to the right. What I mean is that you can determine your path and calculate the force by considering the weight and gravity, which is why you apply the force to the bird. I think it's the best way, and also the most realistic.

share|improve this answer
add comment

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.