Jump to content
  • Advertisement
Sign in to follow this  
garyfletcher

Directing obects after collision detection

This topic is 4968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. Am pretty new to all this games development and am reading Beginning .Net Games Development in C# to begin with. I eventually plan to go on to C++ for speed, but that it by the by. Anyhow. I have been reading the book, developing and adding to the games in the first two chapters and have decided to write an extra two games under my own steam using the methods set out in the book. The 1st game will be a variation on PONG the 2nd a variation on Breakout. Both will be in 2-D (wil tackle 3-D later) and both will need methods to calculate projectile direction after hitting a pad/bat/axis limit/block etc. I have been looking at the internet to try to find a suitable method but, as of yet, nothing. There is lots about collision detection but nothing about projectile direction after collision (either that or I'm looking in the wrong places). Have though about using the x and y coordinates prior to collision and some sort of transformation function, but then I wonder about using the angle from which the projectile was travelling and simple geometry maths. Anyhow, am a bit confused so if anyone could point me in the right direction I'd be grateful. Also if you could suggest a method to include friction and bounce to calculated acceleration/deceleration I'd be eternally grateful. Cheers Gary.

Share this post


Link to post
Share on other sites
Advertisement
Here is how Torque does it:

Vector3 bounceVel = currVelocity - normal * (Dot( currVelocity, normal ) * 2.0);

Basically it works like this:

Measure the angle between the velocity vector of the object and the normal of the object it is colliding with. Multiply the normal vector by that amount * 2. You have to do the *2 otherwise the new vector will not have the correct angle of reflection. Then subtract this vector from the velocity vector of the object that is moving around.

This will give you the new direction the object should be going in. Simply find the point of collision and from there move the object in the new direction. Of course, it is not as simple as this as you have to deal with corners and other fun things.

Since you are only dealing with 2D, you can simply drop out computations for z.

Hope this makes sense.

Chris

Share this post


Link to post
Share on other sites
In general, you want collision results to be an input to your physics simulation. Typically, you will create penetration constraints, that try to push the intersecting objects out of each other, and the next step of integration will take care of resolving momentum with regards to forces etc.

Share this post


Link to post
Share on other sites
On a very simple level, if you're only going to be colliding objects whose faces are aligned with the X and Y axes (as in just about every version of Pong or Breakout), there's very little you need to do. If the ball collides with an X-aligned face, invert the Y component of the vector representing its velocity. For collisions with Y-aligned faces, invert the X component.

It's a bit different for the paddle, if you're going to change the normal depending on how close to the centre you hit, but of course corliss has explained how do that :o)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!