Hi,
I am trying to precompute the trajectory of a ball going through a world of dynamic and static objects. You can see a video here to understand what I mean. On the video, there is a white/gray line showing the trajectory. I did it the following easy way:
- Running the simulation multiple times in a row and saving the position of the launched ball each frame. Then I reset every thing that moved during this simulation.
It's working but it's extremely slow. Here are a few ideas to optimize that I already had (and tried for most of them):
- Set all dynamic objects as static to speed up the computations. I tried it, it speeds things up but of course, the collision response is wrong.
- Precomputing the trajectory without any collisions. Then use this trajectory to simplify the world update (no need to update the main ball). I am not sure this will speed anything as the collision detection is what is taking time. It would probably require many hacks in the box2d engine.
- Doing it in multiple frames : some objects are moving across the screen, it would give wrong results
- Using raycast : tried it: if my ball is hitting an object on its side, the precomputed trajectory doesn't get it as rays have no width.
So, do you guys have any ideas on other things I could try to achieve this?
Thanks for your help!
Dave.
I am trying to precompute the trajectory of a ball going through a world of dynamic and static objects. You can see a video here to understand what I mean. On the video, there is a white/gray line showing the trajectory. I did it the following easy way:
- Running the simulation multiple times in a row and saving the position of the launched ball each frame. Then I reset every thing that moved during this simulation.
It's working but it's extremely slow. Here are a few ideas to optimize that I already had (and tried for most of them):
- Set all dynamic objects as static to speed up the computations. I tried it, it speeds things up but of course, the collision response is wrong.
- Precomputing the trajectory without any collisions. Then use this trajectory to simplify the world update (no need to update the main ball). I am not sure this will speed anything as the collision detection is what is taking time. It would probably require many hacks in the box2d engine.
- Doing it in multiple frames : some objects are moving across the screen, it would give wrong results
- Using raycast : tried it: if my ball is hitting an object on its side, the precomputed trajectory doesn't get it as rays have no width.
So, do you guys have any ideas on other things I could try to achieve this?
Thanks for your help!
Dave.