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 making a game with Andengine and Box2D. I have a dynamic body and I apply linear impulse on the body to move it around when the user have touched the screen.

Now I want to show the path where the body will go when the user have touched. If you have played Angry Birds or Basket Ball Shoot or any other which have projectile motion with a path shown you will get my point. I want to show the white dots which are shown in those games.

share|improve this question
add comment

2 Answers 2

To get the best result, you need to run the simulation like if you actually threw the projectile - just fast forward! And that is quite easy in any Box2D port. In AndEngine call method step(float timeStep, int velocityIterations, int positionIterations) from class com.badlogic.gdx.physics.box2d.World in a loop to run it as fast as you want. You can apply arbitrary forces at the beginning or between each two steps.

Note that in AndEngine the World class is wrapped in class PhysicsWorld that doesn't give you direct access to the instance of World. However you can extend PhysicsWorld to get access to protected fields, or you can simply call onUpdate method. This one updates all AndEngine physics connectors as well.

Just be careful with the performance, play with the parameters. Maybe create a clone of your physics world that will be simplified, containing just the objects directly needed for the simulation.

share|improve this answer
    
How does World differ from PhysicsWorld? I don't even reference World in my game. I'm wondering the relationship between these so I can implement a feature similar to the "dotted line arch" in Angry Birds. –  unexpected62 Jun 25 '13 at 4:09
    
@unexpected62 I have added some information to my answer. You are right, there is no direct access to World. Let me know if this is enough. Alternatively, check the source code of PhysicsWorld class. –  sm4 Jun 25 '13 at 4:57
add comment

Two options come to mind, although I don't know if either is the most efficient route. (I also have no idea if your libraries already have functionality for this).

Option 1 is to simulate the path of the body each time the touch location changes, and draw a line or dots across the path. The advantage is that this will definitely give you an accurate path at the expense of unnecessary computation.

Option 2 is to derive an algorithm using quadratic equations etc to draw the dots based on a simple parabola. This would require knowing how the engine simulates the movement of the dynamic body. Advantage is that this is far more simple and scalable from the perspective of computation, but it won't lend itself well to changing the physics of the system, not to mention difficult physics math.

share|improve this answer
1  
Note that if you take option 2, you probably want to do a form of collision detection/hit check on your parabola so that it only goes up to the first point of contact - that's the classic approach for handling these sorts of things; it shows the player the key first chunk of the path, but leaves open some mystery in the subsequent chaos of the trajectory. –  Steven Stadnicki Jul 25 '12 at 22:34
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.