Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Making a ball bounce back and forward in Pong replica
Forum Updated to NodeBB v4.3 + New Features

Making a ball bounce back and forward in Pong replica

Scheduled Pinned Locked Moved General and Desktop
pongballmotioncollisions
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nanoandrew4
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • R Rondog

        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.

        N Offline
        N Offline
        nanoandrew4
        wrote on last edited by
        #3

        @Rondog Will look into vectors, right now I am just looking at the ball bouncing back and forth, but will want to implement more complex movements later. Thank you for your answer.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved