Collision Detection

Ok, i know this has already been posted on but after going through that i still couldn't get it to work. So here's my code and plz tell me what's wrong.

Texture2D _paddle1;
Texture2D _paddle2;
Texture2D _ball;
Vector2 _paddle1pos;
Vector2 _paddle2pos;
Vector2 _ballpos;
Vector3 _p1box;
Vector3 _p1box2;
Vector3 _p2box;
Vector3 _p2box2;
Vector3 _bbox;
Vector3 _bbox2;
BoundingBox bb1 =newBoundingBox();
BoundingBox bb2 =newBoundingBox();
BoundingBox bb3 =newBoundingBox();
SpriteBatch spriteBatch;

_paddle1pos =newVector2(50, 300);
_paddle2pos =
newVector2(1000, 300);
_ballpos =
newVector2(400, 300);
_p1box =
newVector3(_paddle1pos.X, _paddle1pos.Y,0);
_p1box2 =
newVector3(_paddle1pos.X + 14, _paddle1pos.Y + 67,0);
_p2box =
newVector3(_paddle2pos.X, _paddle2pos.Y,0);
_p2box2 =
newVector3(_paddle2pos.X + 14, _paddle2pos.Y + 67,0);
_bbox =
newVector3(_ballpos.X, _ballpos.Y,0);
_bbox2 =
newVector3(_ballpos.X + 33, _ballpos.Y + 32,0);

bb1.Min = _p1box; bb3.Min = _p2box; bb2.Min = _bbox;
bb1.Max = _p1box2; bb3.Max = _p2box2; bb2.Max = _bbox2;

if (bb3.Intersects(bb1))
{
_ballHspeed *= -2;
_paddle1Hspeed *= -2;
_paddle2Hspeed *= -2;
}
if (bb3.Intersects(bb2))
{
_ballHspeed *= -2;
_paddle1Hspeed *= -2;
_paddle2Hspeed *= -2;
}
if (bb1.Intersects(bb2))
{
_ballHspeed *= -2;
_paddle1Hspeed *= -2;
_paddle2Hspeed *= -2;
}

Thanks,
DragonC#

[4098 byte] By [DragonC#] at [2007-12-26]
# 1
Maybe if you tell us what's happening we can better help.
JimPerry at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2
Sorry, it was late 2:00 in the morning to be exact. Ok above you can see i decleared my boxes, but when the program runs the ball still goes right through them, no collision. That is where my problem is and thanks for replying.
DragonC# at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 3
Your code does not actually call any intersection routines.

For each time step, you have to check each object against any other object it may intersect, and if you find that they're moving into each other, handle the collision by affecting the position, velocity, or forces on your simulated objects. XNA is not a simulation engine, and does nothing of that for you.

JonWatte at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 4

You're also doing this:

_paddle1pos = new Vector2(50, 300);
_paddle2pos =
new Vector2(1000, 300);
_ballpos =
new Vector2(400, 300);

which means you're never checking the paddle or ball against an updated position, it's always a hard-coded position. Where is this code in your project?

JimPerry at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 5

Ok heres the code that moves the ball

_ballpos.X += _ballHspeed;
_ballpos.Y += _ballVspeed;

int BallMaxX = Window.ClientWidth - _ball.Width;
int BallMinX = 0;
int BallMaxY = Window.ClientHeight - _ball.Height;
int BallMinY = 0;

if (_ballpos.X > BallMaxX)
{
_ballHspeed *= -1;
_ballpos.X = BallMaxX;
}
else if (_ballpos.X < BallMinX)
{
_ballHspeed *= -1;
_ballpos.X = BallMinX;
}
if (_ballpos.Y > BallMaxY)
{
_ballVspeed *= -1;
_ballpos.Y = BallMaxY;
}
else if (_ballpos.Y < BallMinY)
{
_ballVspeed *= -1;
_ballpos.Y = BallMinY;
}

And the paddles are the same for the collision testing.

DragonC# at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 6

After i read your post about ten times i realized what you where trying to say thanks

DragonC# at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...