Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Collisions, objects moving towards each other. Bullet physics etc.  (Read 2477 times)

0 Members and 1 Guest are viewing this topic.

Karsomir

  • Newbie
  • *
  • Posts: 14
    • View Profile
I've got my collissions up and running ( up to a point ). In 1 situation if my moving object ( ball ) hits a stationary object everything is cool, 1 collision detected and behave as expected. Problem begins when an object moves towards other and second moves towards first as presented in situation 2. Then I get 2 collisions and I would like to get rid off such inconvenience. For learning purposes im using 1 pixel per frame movement for both objects so it is easier to understand. Collision checking is very simple and its basically something like this:
if( Rect.intersecting other Rect ){ then move away by one pixel }
in gameloop.
Since I like pictures i've drawn it, so here's pic:   


My question what's the solution? And maybe what are advantages and disadvantages if there are multiple solutions?
And the second question is kinda related, I guess ...  When we get into higher velocities, let's say ball is moving twice as fast ( 2 pixels per frame! :) ) then similar situation happens, except when we get 10 times speed we miss collision completely. It's called tunelling/ghosting but I need more details about how to solve it. Do I need prediction of movement, or checking ( sweep ) after? How to get actual point of collision?

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Collisions, objects moving towards each other. Bullet physics etc.
« Reply #1 on: August 18, 2013, 11:16:47 pm »
if( Rect.intersecting other Rect ){ then move away by one pixel }
while( Rect.intersecting other Rect ){ then move away by one pixel }

Edit: You can check before moving if you would miss a collision and then move it step by step, thats how I would make it.
« Last Edit: August 18, 2013, 11:21:06 pm by Geheim »
Failing to succeed does not mean failing to progress!

Karsomir

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Collisions, objects moving towards each other. Bullet physics etc.
« Reply #2 on: August 19, 2013, 05:51:15 pm »
Nvm, I figured it out. I'm using simple detection ( not any sophisticated sweep test predictions ) anyway, if anyone will encounter similar problem, I did two way collision checks, for paddle->ball and ball->paddle.

 

anything