Skip to main content

Report this content

We want the Dreams coMmunity to be a safe, diverse and tolerant place for everyone, no matter their age, gender, race, sexual orientation or otherwise. If you believe this content to contradict these principles, you can file a report for our coMmunity teams to investigate.

Note that misuse of the reporting tool will not be tolerated.

Item being reported:

A forum post by cgCody

So I was thinking about the 8 directional logic part you already worked out, and how I might go about it. I realized you can actually do it with just 3 nodes. If you multiply the direction vector by the secant of 45* (sqrt 2 or ~1.414), round it, then divide it by sec 45*, you get your 8 directions. (For the player character, this value has to be normalized, for the NPC, it does not.)

There's technically more accurate math for this, but it requires way more nodes, for imperceptible gains.

I made a remixable example, but feel free to just take note of the logic and implement it on your own.
https://indreams.me/element/oBukaehwTdw

Oh dear! Your browser is either unsupported or there has been a problem loading the page.