How i can make player to dont go inside walls

An idea i have is to create a class that draw an model, in that constructor i will add also some informations about model like ID-NAME-Position.

So i will create an function that will check if

if ( Abs(Player.XYZ - Wall1.XYZ) < 500)
       return;

But as you understand this is not possible when you have 100 objects, you cant have 100 ifs.

So any idea to solve this problem? thanks.

No matter what, collision detection is just going to be a bunch of if() statements. The way that you prevent checking way more objects than you need to is by dividing all your objects into a quadtree or an octree. You then check if your player is within one of the outer nodes and if it is then you work your way in to see what objects you are colliding with.

You should make a program that loops 1000000 times with an if() statement in it and see how many milliseconds it takes. You will be suprised at how little time doing if() checks take.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.