# Show path of a body of where it should go after linear impulse is applied

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.

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.

• 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. – boltup_im_coding 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

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.

• 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