We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C#-XNA How to detect walls?

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.

2
Contributors
1
Reply
22 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
Panathinaikos22
Junior Poster
136 posts since Aug 2011
Reputation Points: -4
Solved Threads: 6
Skill Endorsements: 0

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.

sfuo
Master Poster
713 posts since Jul 2009
Reputation Points: 173
Solved Threads: 111
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0661 seconds using 2.69MB