Super Simple State Machine!

Hey all! How’ve you been?

I’ve been very busy lately. I know I don’t post often enough, but I’m working on changing that up. And, for starters, I’ve posted a brand new tutorial! Been a few years since I’ve done that, right?

Well, for you AI newbies, I’ve posted a tutorial for a Finite State Machine I made a few years ago, affectionately called the Super Simple State Machine. I even posted the code and a Unity package demo project up on my GitHub for you. Isn’t that nice?

Give the tutorial a look-see, let me know if you like what you see and you want more.

That sounded really dirty… Sorry about that. Later!

Advertisements

Link: Two’s Complement

Link: Two’s Complement

You wanna know what always used to break my brain back in school? Two’s complement. For those of you unversed in nerd geek, i’s the computer’s way of interpreting negative and positive binary numbers by using the left-most bit as the sign.

Examples:

Lets talk in nybbles here (4 bits instead of 8). In a perfect unsigned world, the number 15 is expressed as 1111 in binary. However, speaking in signs, this is -1.

Continue reading Link: Two’s Complement

Link to the Path: A* Pathfinding for Beginners

A* Pathfinding for Beginners

OK, so a while back I posted a link for a simple implementation for A* Pathfinding for C/C++. The page gets a bunch of hits, but I get a lot of people asking me to explain it. Well, it’s not my code to really explain, and I haven’t tested it out for myself. Rather than go through and make a huge tutorial, I figured I’d take the lazy route, and provide you with a resource to help explain it a bit. This page breaks down A*Pathfinding to the basics and gives a great explanation down to even the heuristics (If you don’t know that word, you’ll need this link).

So, now with this in hand, pathfinding should be easier to grasp now. Give it another go, and let me know how it turns out! Good luck!

Quick Code Tip: Fix Precision with Floating Points

Let’s say you have a floating point value of 200.21, and you convert it to an int, like so:

int amount = (int)(famount * 100);

Depending on processor, libraries, compiler and tons of other stuff, your value may APPEAR to be 200.21, but when you do your conversion the value comes out to 20020. What happened to that extra 1?!

Well, though you may see 200.21, the computer is actually storing 200.209999999… (because, you know, 0.999… == 1).

This doesn’t happen all the time, but when it does, it’s a pain. So how do we fix this?

Just add 0.5. Seriously.

int amount = (int)((famount * 100) + 0.5f));

Bam. Let’s break this down, PEMDAS style.

(famount * 100)
Ok, so we know that famount is not 200.21, but 200.2099999… This now brings us to 20020.99999…

((20020.999…) + 0.5f)
The 0.5 now brings us to 20021.49999… Like magic.

int amount = (int)(20021.4999…)
Saving all the pennies.

Good job. You just saved the world from mathematical inaccuracy.

Until next time, take care. (After that, do whatever the heck you want.)

Math Magician: Much Ado About 3D Math

Illustration of the right-hand rule for the cr...
Image via Wikipedia

You know what irks me? Going online to look up something simple, like Dot Product or Cross Product, and getting nailed in the face with calculus proofs and discrete mathematics on why this and that happens, but never getting a simplified answer on what I’m looking up!

Well, I have a website, and now it’s time I delivered the simple answers. Open wide for a study guide. Continue reading Math Magician: Much Ado About 3D Math