XaiJu
Megan Fox
Megan Fox

patreon


Math Checks Everyone Needs

Merry Christmas $1 backers, you get a code-tier post. Merry Christmas $3 tier backers, you get a HUGE list of functions that just about everyone should have somewhere in their codebase.

Mostly I just want to make sure EVERYONE has these.

We're all programmers here, so hopefully everyone knows why "== 0.0" is a super dang bad idea most of the time. Or even why "floatA == floatB" is a bad idea. You don't? Oh dear, read this.

Ok, everyone on the same page? Great. Now read the source I've provided. I make no claims that these are particularly good examples of the form, but included are IsNear(), IsNearZero(), IsNearOrUnderZero(), and ClosestPointInLine() - most of which in a few different argument flavors. Just throw these into a util library somewhere. Turn them into extension methods if you like. But use them or something like them, I beg you.

You'll also find IsCloseEnoughToStop / IsFarEnoughToMove. These are fiddly little functions useful for when you want something to keep moving until it gets within X of another thing. If that thing is mobile, it's really hard to get your follower to ever come to a nice stop, it'll just kinda... twitch, as it follows. These 2 functions help it get close enough, stop, wait, go "god dammit it's getting away again", THEN start moving again. Simple, but, makes following behavior that little bit less weird looking.

Cool? Cool. Happily wotsit everyone. Merry thingy.

Math Checks Everyone Needs

More Creators