As a part of the quick game I'm working on now, I'm having some NPCs attempt to chase after you, taking the most direct route possible.
At first when I was planning it out, I thought I could just set their X and Y speeds to be able to have them move at the correct angle when moving diagonally. However, I have now noticed that the only commands I can queue for them are the cardinal directions. Is there a way to queue COMMAND_MOVE_NORTHWEST, etc., or do I have to individually queue COMMAND_MOVE_NORTH and COMMAND_MOVE_EAST?
Alternatively, is there a better way to do this? This may just be a case of the classic XY problem, but it was my best solution.
You'll need to do something like:
QueuePersonCommand(name, COMMAND_MOVE_NORTH, true);
QueuePersonCommand(name, COMMAND_MOVE_WEST, false);
Notice the 'true', it'll make that action happen immediately so all you'll see is a diagonal northwest movement. I've always disliked the fact you can face diagonal, but you can't move diagonal in Sphere. So, this code has got to be custom added.
Maybe it has to do with something along the lines that normally moving "diagonally" would cause you to move faster than the game physics intends you to? That's my first guess.
Damn, I was going to say minisphere supports using diagonal directions directly, but it turns out I never actually implemented those! The constants are exposed to script, but if you queue one nothing will happen. Whoops! Looks like it's time for another hotfix!
Note that, despite this, I would still recommend using Radnen's method if possible. That is what the engine does internally when moving diagonally, believe it or not. The reason being, a direct diagonal movement only does one obstruction check, whereas queuing north and west separately does a separate collision check for each command (Lithonite depends on this behavior, in fact), making it less likely the person will get caught up on corners.
Edit: Actually, I think I will set up minisphere to do this too: If you queue a diagonal direction, it will split it into two commands internally.
Okay, new version of minisphere is up. Starting in 1.1.8 you can directly queue COMMAND_MOVE_NORTHWEST, etc. and it will work as expected.
I love that I have my own Sphere engine now, it's so convenient. Over the years there were tons of little things like this that I wished Sphere included, but had to make do without. Now I can just open Visual Studio and code it in myself, no sweat. ;)