Tuesday, May 10, 2011

Vectors, Velocities, and movement patterns: How to drive a guy nuts.

This *should* be a quick update since I want to get to bed here pretty soon.  Like, four minutes ago!  Just great!
Not that I have experience with this, but I'd imagine it's the same feeling.
What have I done in the game today? SOMETHING TANGIBLE!
(this good news people!)
What exactly have I done?  I've just implemented a few enemy movement differences that help enemies move smoother/smarter.  The basics of what I did was smoothly adding velocity to enemies instead of adjusting their position by physically altering their X-and-Y positions every step of the game (which also made for pretty bad collision checking problems, too)
Movement, everybody, movement.
How I did this was pretty simple but I doubt I can explain it much outside of the context of XNA, so if you don't know programming... well I can try, anyway.

Basically I used these thingys called "Vector2" 's in XNA which correspond to having an X and a Y value, as well as a length or magnitude or what will you (I hate to admit it, but yes, I do use math.  Only a little bit, though, it's okay)  This magnitude extends to an X and Y length.  At each step in the program the sprite/image/object is moved X units by Y units in the game space by the length of my velocities X and Y.  If you think back to trig... (oh no!) you can recall that having an X length and a Y length connected means, you can get a third length, called the hypotenuse that with the other two lengths forms a triangle.  I basically fudged my way along to make sure I can alter this length or magnitude which is the number of steps X and Y my objects can move in a step.


That probably didn't make sense, but I tried.  It was simple stuff regardless, just a bit time consuming.
I figured it's about time I drew something that WASN'T terrible violent...
The second step that I was working on up until I started writing this was adding a method for enemies to have a stored list of targets that they can move to and cycle too.  Again this stuff isn't too terribly difficult, I just have a new object that stores a list of positions in 2D space, along with a certain time allotted for each position (after the time has run out, then the enemy moves to the next location in the list and so on and so forth.  It's very primitive but I hope it will work for the purposes of the game.  I'm still working on the system, mainly how to create lists of points that we can use and re-use (and name) to give the game some elements of strategy to it, and not just random-falling-gunplay.

Stand back: THIS IS SCIENCE
So yeah, there's a quick update of the game.  I didn't get as much done today as I wanted too, but what can I say, I had school and today was absolutely beautiful outside.

Well, minus the humidity.  Something I've learned isn't so amazing about the midwest is humidity.  Give me dry weather any day, man.  Humidity just makes me sweat profusely.

So, uh, yeah that's it.  Thanks for stopping by!

OH YEAH.  My best friend from home, Terrence, finally got a phone so we can talk again.
Happyface!
So keep on the lookout for a join Kevin-Terrence blog, we are talking about doing one.  Not like this, just joint artwork, solo work (he is a much better artist than me, for one thing he's actually an artist!)
It would also include us just talking about things (Games, music, art, girls, things that concern guys, haha) and possibly stuff like short stories or philosophical writings.  When me and T get together, you never know what's gonna happen!

Anyway, G'night interwebs.

- Kev
Don't you just hate it when that happens?

No comments:

Post a Comment