Making a ball bounce back and forward in Pong replica
-
I have been trying to make a ball bounce back and forwards after colliding with objects, and every time it touches an object, it glitches and does not bounce back. I realize that using collidingItems() is only true after a collision, and as soon as it bounces back it is set to false again. What I am wondering is how to make it so that after a collision it bounces back.
Current code in Ball.cpp
http://pastebin.com/rzHnP5WN -
Have you looked at the examples included with Qt (QGraphicsView / QGraphicsScene). I think I remember a demo application included with Qt showing randomly moving items with collision detection.
For dealing with how to bounce (math to calculate new vector and speed) is another thing all together. For a simple bounce on a vertical edge you would simply reverse the X axis vector. If the item is traveling -X+Y then after contact it will travel +X+Y with the same speed it had previously. For complex shapes with different sizes (mass) it becomes a bit more harry.