Day 2: 12 January 2013
10:22: I’ve been at it for another half hour now. I’m working on figuring out how to get ships to move to a particular location. This, of course, is one of the key building blocks to a space RTS game. It will be necessary to be able to do waypoint navigation as well as being a key part of moving to attack something.
Stirring in the back of my mind is the thought that maybe I’m making the wrong game. Maybe I should be making a space fighter combat simulator. Not all that different from TIE Fighter, or the like. I don’t know. I’m probably just seeing the results of the rubber meeting the road, and beginning to get a feel for what I’ve gotten myself into…
10:41: Well… I got my ship to go in the opposite direction of where it’s supposed to go. Guess I’ve got a vector backwards somewhere.
10:43: There it is. I had a vector subtraction backwards. (A – B instead of B – A.)
11:06: Oops. I forgot to start my Pomodoro clock. Anyway, I got my waypoint navigation up and running. The next thing that would make this cool is to be able to select ships and then tell them where to move. I’ll tackle that after a short break. I also think I’m going to go detail what a Pomodoro is, for the sake of completeness on this blog.
11:46: That’s three pomodoros down for today. I’m doing one more and then taking a slightly longer break. I’m currently trying to deal with line drawing in XNA. For some reason, it seems like they never really figured out how to make this easy in XNA. I’ve always been disappointed in that. I mean, you can draw a model with a wireframe, but just drawing a bunch of lines is common enough, it should have been a bit easier. (Not that it’s impossible or anything.)
When I get it working, I’ll outline the process I followed. This would be an excellent addition to my XNA tutorials….
11:53: Just wasted 10 minutes or more trying to figure out why my lines weren’t being drawn. I forgot to send the view and projection matrices off to my shader. How many times do I need to learn that mistake before I remember it permanently? :)
12:16: I’m going to take a slightly longer break now and grab lunch. But here are a couple of screenshots that show the line grid and the waypoints. Still a very long way to go.
13:16: I’m back. Ready for at least another two hours.
You know what’s an excellent resource for making games with XNA? rbwhitaker.wikidot.com. Yeah, I know. That was shameless. But seriously. In just the five hours of work that I’ve put into this game, I’ve used my site probably a dozen times. It helps that I know in great detail, everything that’s covered there, and where to find it, but it has been incredibly helpful.
It makes me think that if everyone maintained their own site full of tutorials, even for just themselves, for the second time they come back to something, we’d be saving ourselves a ton of time.
Somebody implement that idea and give me 2% equity in the company for the idea…
14:03: I got my grid being generated based on where your ships are. Well, where one of them is, anyway. The region where the grid is indicates where you’ll be able to see enemy ships. I just need to generate it for all of your ships and combine the set of grid lines into one overall grid. I have to say, at least that little piece is looking pretty decent.
14:27: I’ve got my full grid working now, regardless of how many ships you have. I don’t really know why I chose to focus on the grid to start. It’s kind of random. The only thing that comes to my mind is that it helps keep the player oriented to what direction is what. It really does accomplish that, but that’s not really why I chose to go into that detail. I just did. That’s probably not the best thing to do.
I really think my next step now is to get some sort of selection up and running.
15:38: I’m now deep in the process of doing picking. It’s taking longer that I’d like, but that’s OK. I know I’ve already got a tutorial on doing picking, but I really need something more comprehensive for this game. I can’t just always use spheres. (Though that’s my starting point right now, anyway.)
It doesn’t help that I got distracted by looking for a space skybox generator. I found one (Spacescape) but it always crashes on me when I try to make a specific type of layer (which I think I need in order for anything to look good). I don’t know why I went off down that path. Skyboxes would add a lot to this game, but I think for the prototype, selection is going to be much more important.
I’m hoping to get selection up and running in the next Pomodoro.
16:16: Well selection isn’t quite working yet. I think I’ve got a bug in my sphere/ray intersection code. I was using a Wikipedia article as a reference. It says (o – c)^2, where both o and c are vectors. After the subtraction, you’re left with a vector. But… one does not simply multiply vectors. That doesn’t have any meaning that I’m aware of. So what does that mean? I can think of three possibilities:
- The dot product of a vector and itself. Th* e cross product of a vector and itself.
- The norm (length) of a vector and itself.
I initially assumed it meant the last one. But after looking at the Wikipedia article a little longer, I’m now thinking it’s probably the first. Also, see this discussion. Apparently I’m not the only one finding the square of a vector confusing. It looks like that’s not the best way to write it because it leads to this ambiguity that I’m seeing. I’m going to make the change and see if that gives me better results.
16:24: I just changed my code and got the same results. That didn’t seem right so I did the math. Guess what? Options 1 and 3 are the exact same thing! Here’s how:
The dot product is defined as the sum of the products of the individual components. That is, if you have a vector <a, b> and another vector <c, d>, the dot product of these two is ac + bd. This also applies in 3D. So if I have a vector <x, y, z>, when I do the dot product, I have x^2 + y^2 + z^2.
On the other hand, the length of a vector is defined as the square root of x^2 + y^2 + z^2. Since I assumed this was the square of the length, that just leaves me with x^2 + y^2 + z^2. It’s the exact same value.
I feel like I should have known that, somehow, with all of the math I’ve done in my life…
So now I have no clue what’s going wrong…
16:30: Bingo! It was just an incorrect +/- sign. Easy fix, once I stepped through the code.
16:42: Selection is all working like it should now, and I’m also drawing a little selection ring when you’ve got a ship selected. The next step might be to add in the ability to give commands to your ships now, but I think I need to step back and think about what I really hope to accomplish this weekend, and what is really needed to get some sort of working prototype up and running. So even though I’ve got four minutes left on this Pomodoro, I’m going to call it quits, take a short break, and figure out what the plan is from here.