Posted by: Wade | June 4, 2008

Update!

So I really havent had much time over the last few months to even get on here and think about posting an update. I havent forgotten about the blog or XNA, I’ve just been moving extremely slow. I’m two weeks away from graduating, and for the last few months I’ve been juggling 3 jobs and school… Needless to say, I’ve been pretty busy.

Anyway, down to the update stuff. I’ve gotten a few friends together and we’ve been talking about getting together to work on an XNA project. We all have tons of ideas that we want to try, so were going to come up with something that we’ll all enjoy working on and have a chance to implement our ideas. I just wanted to give and update to everyone as to what was going on, and to let you know I’ll keep track of our development on my blog whenever i can.

Posted by: Wade | January 8, 2008

XNA 3D Collision Detection using Bounding Shpere

If you’ve been forllowing this blog you’ll know i’ve been making a game. It originally started as an assignment for my XNA development class, but I grew attached to it and have turned it into its own project. Anyway, if you want to know more read the post below this one!

When beginning to do 3D collision detection, i thought the easiest way would be the “bounding box” method. If you don’t know what that is and would like to know more, just google it, there are tons of tutorials. However, for my particular use, this was no good, and it takes a little extra time to code it all out.

If you are using simple models in your game (currently mine just uses cubes to illustrate the basic gameplay) then you can probably use the other method of bounding sphere, thats already built into XNA! When i found this it was like a life saver, although I already coded the bounding box, i removed it and replaced a few lines and I was ready to go.

Basically for each model you load in XNA, the framework automatically creates a bounding sphere for that model. What most people have a hard time understanding is that if you move the model in game, then the sphere doesnt follow. So really if you drew all your bounding spheres they would probably be right where you loaded the model. So remember when using model.BoundingSphere() you have to create a new bounding sphere to move around. It’s not as hard as you think here are some examples:

In the variables for a troop i have this:


        public BoundingSphere bs;
        public BoundingSphere range;

“Bs” is the actual bounding sphere of my “troop” model. I just steal the position of my troop when i first load it to give the bounding sphere the proper location. The “range” bounding sphere is just another way of showing you what the bounding sphere can be used for. Each of the weapons have a range, and this sphere’s radius, is the number range of that weapon. So if a target is in range, we can shoot at it! Kind of neat to use bounding sphere’s in that way.So how do we use a bounding sphere and why are they so easy? Here is some more code to initialize the sphere:


                foreach (ModelMesh mesh in model.Meshes)
                {
                    Vector3 center = mesh.BoundingSphere.Center;
                    float radius = mesh.BoundingSphere.Radius * scale;
                    center.X += position.X;
                    center.Y += position.Y;
                    center.X += .5f;
                    center.Y += 2f;
                    bs = new BoundingSphere(center, radius);
                    range = new BoundingSphere(center, w.getRadius);
                }

It looks like a lot but it isn’t i promise. Bounding sphere’s are actually in the mesh part of a model, for my classes they all hold their own model, and when i draw i just tell my application what were drawing and it has the model. So, were going through all the mesh parts and moving there bounding box accodingly, for mine we only have one, and your method might have to be different for multiple mesh parts to a single mesh.
Each bounding sphere has a center, and a radius. The center is an XYZ coordinate, and the radius is a float saying how large it needs to be, so in essence my range is just a different float for each weapon. Once you set all that you should have your sphere moving with your model in no time.So now my troop has a bounding sphere, we have to make sure we move that with the troop so whenever we make the troop move, make the sphere move too. Thats the most important don’t forget to do that or you’ll have a hell of a time wondering why you’re shooting something and it never collides.

Alright, now for the second part! I have another class, this is a projectile class that i use to show a yellow “bullet” firing. These are really small low poly models that also have a bounding sphere. It also moves with the bullet as it is fired; so how exactly do we check to see if a bullet hit something? Oh, how you wonder. Luckily you are using the bounding sphere and it’s SO simple:


bs.Intersects(troop.Target.BoundingSphere)

Don’t get consfused, i pulled this from my projectile class so “bs” is the bounding sphere of the bullet. In my game, each troop is shooting at a target troop, not just a random area, so were getting the target troop of the bullets owner. Basicall, whoever shot the bullet, were getting who they are shooting it at. Once we have that we just check to make sure the bounding sphere for the bullet, intersects the bounding shpere of their target, and if it does we lower the targets health.Now this is really simple and it only works if they hit their target, if another enemy happens to cross the line of fire, the bullet would continue until it either hit’s or misses it’s target. You can extend this to have more functionality, so if anything crosses the bullet it’s going to get hit.

Posted by: Wade | December 17, 2007

Updates

XNA Game ScreenI think an apology is in order. I’ve been extremely busy with school and unable to really even pay attention to my blog, and that’s really unfortunate. I apologize about that.

In some other news however, I have finished my XNA class and it’s proven to be quite the class. For our final project I was told to “make a game, something cool and complete” so thats what I did. To the left is a screenshot of the game I created, i know im not a modeler or graphic artist, but this game holds a lot of conecpets that are really important to programming XNA. I plan on writing a series of tutorials to help other learn what I did while i was creating this.

It’s a simple concept for a game, I personally like messing around with AI, and seeing how things work, making the computer act on it’s own to decide how things play out, yet at the same time I like allowing the player to affect how the game goes. Taking this idea and running with it a drew a quick concept up on my whiteboard, it was basically a square level, with teams of red and blue squares that would fight eachother. The only thing the player would be allowed to do is pick a weapon to fight the computer with. Based on what type of weapon you chose, you would have different damage stat’s etc… The computer then plays out the battle, both teams are non controllable and based on random movements they fire at eachoter when in range, once one team is eliminated the game is over, and reset’s.

There are quite a few bugs as I was rushed to turn it as my final project, but i’m happy with how it turned out and plan on keeping it up and turning it into something decent. Thats another story within itself that i’ll just have to keep you updated.

Posted by: Wade | November 2, 2007

Out With the Old, In With the New

I’ve done my manerbomb project to the point where i don’t want to see it anymore. 2D graphics are just not my thing, I love the beauty of a nice 3D environment, and 2D just cant give me the fix I’m looking for. If anyone is reading this and wants the source to manerbomb, you’re more than welcome to it.

With that being said, it’s time for me to move on. Ever since I started doing managed directx 9, i’ve been wanting to code a game of some kind that would be fun to work on, but at the same time interest others. While I was crawling the internet last week I stumbled across a game which I thought was amazing. No, it doesnt have good graphics, no its not really up to date, but it was fun and a great idea none the less. I figured it was about the caliber that I could start with, so I e-mailed the creator, and asked for permission to make something similar to what he had made, and I was off.

So what exactly is it that I’m working on now, well it’s an idea based off of the game I came across called AI Planet. It’s actually open source and you can play the 1.1.1 version if you download it from here: http://aiplanet.sourceforge.net/. To explain, the basic idea of the game is to create a planet! You cannot actually control what happens there, but you can contol the aspects that effect it. You can add creatures that evolve and plants that live and grow, then basically you just watch it develop and prosper, or you watch it die.

I’ve decided that rather than take that idea and just re-make it, to create a prototype first to allow me time to learn XNA and AI a little bit. So far I’ve been doing some fun stuff. Working over the last week or so, i’ve generated some terrain on the fly and shown how i find the levels of that terrain.

I’ll keep updates here as i go along, for now there really isn’t much to see, and I’m working on fixing a bug with the terrain generator. Once i flatten that issue out, I’ll post a screenshot!

Posted by: Wade | October 19, 2007

2D Collision Detection

The big game development question in my opinion is collision detection. This is where you’re CPU hates you, and you hate you’re game because it starts running slow. Luckily in a 2D enviornment we really dont have to worry about that. We check the X and Y axis’ to see if there is a colission, and then process our game logic for that particular collision. In a 3D enviornment we do one for the Z axis as well, not to mention that were doing that 60 times per second if our average frame rate is 60. In a 3D enviornment this can make or break your game, if you do not use the proper algorithm your game can slow to a crawl in no time.

So what is the most common type of colission detection? The bounding box. Basically in a nut shell, for the X axis were going to draw two 2D sprites, find the centers. Now we want to take the distance of the centers for those two objects, and subtract them from the sum of the half-widths of each object, if that makes sense. Basically this algorithm will tell us if we’re overlapping, if we are, then there is a collision and we need to do something about it. If we arent, then we just continue.

Using that description hopefully you can understand how that gets big quick! We need to do that for all our objects every frame. If were making a big game, like bomberman, were going to have hundreds of objects at any one given time, including explosions and bombs.

I’m going to write a tutorial on this subject and hopefully bring some light to the world of collision detection for those of you who are still lost. Thanks for reading!

Posted by: Wade | October 15, 2007

Welcome!

Hello? Is this thing on? Okay, good. Welcome to the XNA Game Development wordpress blog, its the official one if you aren’t sure. Not that i need to say that, because if you are reading this you’re probably one of the first, and thank you. Thats probably not all you are, you’re probably asking yourself, “What are your current and/or future plans for this XNA Game Development WordPress Blog?” Okay, maybe not exactly like that, or maybe not at all but I’ll tell you anyway!

XNA Game Development is becoming bigger and bigger within the gaming industry. In fact most games made for the XBOX 360 are using XNA these days! Basically I’ve gotten the chance of a lifetime, or so I think… I’ve gotten the chance to take an XNA development class in college. I think its officially the first class I’ve been obsessed with, and I want others to see what XNA can do, and how to do it. Hopefully I will be able to keep things up to date here, and even have extra time for tutorials or something if you all want. Just shoot me and e-mail or comment, if you want to see something, or even want to help create content; I’m open to anything… Well…. Anything within my moral standards. Hah.

Thats was great! Now you’ve come here, and you know what were all about. Check out the projects page, these are all the side projects that I’m going to be doing for XNA, as well as the assignments I’ll have to do for class. I figure as long as I’m doing XNA, I might as well share it with everyone else!

Thanks for reading, and please keep doing it!

Categories