# avros algorithm working backways and i cant see why

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

## Recommended Posts

i am using avros algorithm here to check if my charachter has hit a wall. all that is supposed to happen if he hits a wall is that a message box pops up.the problem is that as soon as he starts moving, the message box pops up, and keeps popping up until my charachter is half way through a wall. then it stops popping up. i cant find whats wrong, even though i know its prob real simple. i dont test the y axis as i dont use it.if it makes any difference, the center of my world, is on 0,0,0.
public bool SphereOverlapAABB(AxisAlignedBoundingBox aabb, Vector3 center, float radius)
{
//there is no need to check y as the charachter does not move along teh y axis(doesnt jump,go up slopes etc)
float squareDistance = 0;
float diff;

//check x
if(center.X <aabb.MinX)
{
diff = center.X - aabb.MinX;
squareDistance += diff*diff;
}
else if(center.X > aabb.MaxX)
{
diff = center.X - aabb.MaxX;
squareDistance += diff * diff;
}
//check z
if(center.Z <aabb.MinZ)
{
diff = center.Z - aabb.MinZ;
squareDistance += diff*diff;
}
else if(center.Z > aabb.MaxZ)
{
diff = center.Z - aabb.MaxZ;
squareDistance += diff * diff;
}
{
System.Windows.Forms.MessageBox.Show("you have colided with a wall");
}

}


##### Share on other sites
Just a typo. You're comparing the squared distance to the (unsquared) radius in the 'if' statement preceding the message box. Just paste in the code from the return statement (which is correct).

##### Share on other sites
saw that, changed it but to no success. i think the reason why its not working is that i have a charachter, in a square room sorrounded by 4 walls. this algorithm works for one wall,but on the rest of them it doesnt. i have a feeling i will have to do the same algorighm out again , for walls that are on the minus side of the x axis. i have been trying this for the past while but with no success. can anyone explain how i should alter this to get it to work for a room sorrounded by walls?

##### Share on other sites
got it sorted. was one of them dumass stupid , problems that my granny could have spotted. was so easy that i couldnt see it.sorry for taking up your time.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633324
• Total Posts
3011364
• ### Who's Online (See full list)

There are no registered users currently online

×