# "simple" colision need help

Hi all

I have some trouble with my dot going through my triangles. The colision detection seems fine if the ball doesn’t go too fast, so it is how the dot react when it colides. This picture shows the area it colides, just to rule that out.

``````void Dot::collision(float a)
{

if(a != 999999)
{

if(xVel>0)          //checks if the ball comes from right or left
{vf_ht=true;}
else
{vf_ht=false;}

var = atan(a) + atan(a)-atan(yVel/xVel) ;  //calculates the angle the dot should go after colision

if(vf_ht==false)
{var=var+3.1415;}

xVel = cos(var) * sqrt(pow(xVel,2)+pow(yVel,2));
yVel = sin(var) * sqrt(pow(xVel,2)+pow(yVel,2));
}
}
``````

This function gets a variable “a” that is the gradient of the side it colided with, and if a=999999 there is no colision.

I want to calculate what angle the dot should go, and then calculate the xVel component and yVel component by using the angle and the length of the velocity vector.

note: xVel and yVel is like a normal coordiante system so positive yVel will make the dot go up.

Hmm, I’m not certain I fully understand this.
What is it doing? And what should it do?
Do you mean when the dot reaches a triangle it should bounce off of it but it continues to go through it if the dot is going too fast?

If that is the case, I’d check to see if the velocity of the dot is causing it to “jump” beyond the area you are checking for a collision.

If that isn’t it, can you provide a little more information?

Also, have you tried debugging it and stepping through to see what the values are when it should have a collision?> Hi all

I have some trouble with my dot going through my triangles. The colision detection seems fine if the ball doesn’t go too fast, so it is how the dot react when it colides. This picture shows the area it colides, just to rule that out.

``````void Dot::collision(float a)
{

if(a != 999999)
{

if(xVel>0)          //checks if the ball comes from right or left
{vf_ht=true;}
else
{vf_ht=false;}

var = atan(a) + atan(a)-atan(yVel/xVel) ;  //calculates the angle the dot should go after colision

if(vf_ht==false)
{var=var+3.1415;}

xVel = cos(var) * sqrt(pow(xVel,2)+pow(yVel,2));
yVel = sin(var) * sqrt(pow(xVel,2)+pow(yVel,2));
}
}
``````

This function gets a variable “a” that is the gradient of the side it colided with, and if a=999999 there is no colision.

I want to calculate what angle the dot should go, and then calculate the xVel component and yVel component by using the angle and the length of the velocity vector.

note: xVel and yVel is like a normal coordiante system so positive yVel will make the dot go up.

Sorry that I proberly formulated it bad.

The colision detection is fine, because it only moves at limited speed, but the reaction upon colision is bad because it sometimes goes through my colision boxes.

At first i thought it was some sort of double colision, that would make it change direction twice so it went trough anyway. Added a counter to make it unable to colide in a few frames, and it didn’t solve the problem. I have tried to check the angle the ball has and the line it’s coliding with, and it seems fine as well.

That makes me think there’s something wrong when i calculate the angle it should go after the colision, which is then i calculate “var” in my code. I have tried makeing a bunch of examples on paper to see if i got the right angle and i do, so i’m not sure where it goes wrong.

The issue most people run into at this point is that if the speed makes the object move at a speed that allows it to move past the obect before the check is made it won’t detect it. Mostly this means the speep in pixels is bigger that thte object width or heigth or both. If an object moved so fast that it moved across the entire screen in one frame would your current system catch it? Don’t think so. Am I wrong? I like to make it so each object checks as it moves and checks a line for collisions on each outside edge at intervals that are far too small not to find average tip of a point kind of collisions. It bugs the crap out of me when I shoot at a spaceship and the shot passed through the wing without hitting it or similar thing.

It is solved now but i’m not even sure why which is wierd. I made some minor things by moving offset, and set a counter to then it could collide again. Now it is only the edges that makes trouble but thats a whole different story. Too high speed would be an issue, but it won’t reach that kind of speed in my program 