Skip to main content

News

Topic: Letting the NPCs move diagonally (Read 1195 times) previous topic - next topic

Letting the NPCs move diagonally
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.
  • Last Edit: June 01, 2015, 09:15:22 pm by mezzoEmrys

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Letting the NPCs move diagonally
Reply #1
You'll need to do something like:

Code: (javascript) [Select]

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.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: Letting the NPCs move diagonally
Reply #2
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.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Letting the NPCs move diagonally
Reply #3
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.
  • Last Edit: June 01, 2015, 10:47:09 pm by Lord English
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Letting the NPCs move diagonally
Reply #4
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. ;)
  • Last Edit: June 02, 2015, 03:06:21 am by Lord English
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan