Skip to main content

Search

8-Directional Movement

  • cgCody

    Well I'm no logic master, but this may do the trick: https://indreams.me/scene/dMuMwQDcrvH

    It gets a vector between the player character and non player character, then normalizes it, effectively giving you the same type of output as pushing the thumbstick in that direction.

    Depending on your directional logic, you might be able to use it to drive a mover.

    EDIT: Updated to include the mover and a container for your directional logic. Basically, It's a follower that gives you access to it's targeting vector for manipulation.

  • Supposer

    I'll have a look into how the logic of this might look. A couple of hints while I think of them though:

    Calculators can handle doing math to fat wires, giving a fat wire result with the operation done on each individual value. So calculating (1, 2, 3) + (5, 7, 9) will give you the fat wire (6, 9, 12). Makes mathing-up fat wires super easy.

    The look-at rotators--and I think simple movers--can take a 3D "direction," which doesn't mind if the vector is normalised or not. So I'm guessing your logic for figuring this out for the left stick would work for snapping the vector for an NPC also.

    Alternative to the pure-math route for snapping would be to make a rig that uses the look-at rotator to rotate a sculpt according to the left stick. Then you could set up trigger zones and such in different areas to know the stick is pointing in that general direction, and use that to dictate which of the 8 directions it should move in. Might be overkill, particularly if you've got the maths the way you like it. But just an alternative thought.

  • 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

  • AndymationB

    I'm don't entirely understand what you're saying, but I'm really enjoying the confident manner in which you're saying it!

    I look forward to checking this out later. Thanks! :D

  • cgCody

    Don't worry, I don't understand what I'm saying half the time either! I just work with a bunch of vector math gurus in the day job, and some of the stuff rubs off. It's all just loose concepts, and vague intuitions. :D

  • cgCody

    Hey Andy, I wanted to take the example I published a bit further with some simple AI actions, and ended up getting a bit carried away. Haha Nothing crazy like the pathfinding stuff others have done, but the enemy can now patrol randomly, follow and attack the player, investigate the player's last known location and direction, then search the immediate area.

    The enemy can occasionally get caught on walls for now, but it works surprisingly well. I plan to develop it further.

    Not that I presume you care to use any of it, just FYI. :)

  • AndymationB

    Awesome! To be honest, I've been distracted by other shiny things for the immediate time, but I'm absolutely going to get back into this soon, and if it's as good as it sounds, I'll definitely use yours rather than poorly reinventing the wheel. :D

Please sign in to leave a comment.