Moving Object Collision Detection

First of all, my question is not entirely specific to C # or XNA, but my code examples will use them.

I am currently trying to create a Pong clone, and I am having trouble detecting conflicts.

Each object has a specific speed (which is Vector2), Position (Vector2, also) and Speed ​​(only floating). Each time the object Update () is called, the position changes as follows:

Velocity.Normalize(); Position += Velocity * Speed; 

At first, I only checked if there was currently a collision between two objects with a simple call to Intersects () from the rectangles of the objects. I quickly realized that I could not only check if the object was currently colliding with another, but rather if the object collided with the object in its path. Just checking that the two objects are currently colliding made the ball go through the oar when the speed was too high.

I tried various things to fix this problem, but none of them seemed to work. I only need a way to check if two objects collided on their way, and if they do, if they were from horizontal, vertical, or both (to change the speed of the ball accordingly).

I don’t have to immediately need a solution, maybe just the basic idea of ​​how to implement this, and I will encode it myself.

Thank you for your time.

+6
c # xna collision-detection
source share
5 answers
+3
source share

See here for a starting point.

http://www.flipcode.com/archives/Theory_Practice-Issue_01_Collision_Detection.shtml

This is a very good idea of ​​all the different collision methods. Perhaps your case is explained here.

+3
source share

I think this link: http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php may be what you are looking for. It describes a flat-plane sweep test, useful when you have fast-moving objects that can pass through a plane within an interval of one frame.

It also gives you the intersection point, which you can use to reflect your path relative to the normal plane and continue the path to the object.

+2
source share

You have a problem with the fact that if one object is too fast, it can transfer a fixed object before calling Update() with detection (for example, it passes through a fixed object).

Extend the shape of the object along the displacement vector with the size of speed: Square [0,0][2,2] with speed [1,0] and speed 10 will create the shape Rectangle [0,0][12,2] =>, which is now located at coordinates [0,0] with size [12,2] .

Now crossed the rectangle with a fixed object. Now you know if they collided.

+1
source share

If two point features have the same position, they collide.

0
source share

All Articles