ID:2553306
 
(See the best response by Ter13.)
Code:
mob
Enemy
proc
triggerAI()
if(src.client)
return
else
while(1)
sleep(10)
if(behavior == "passive")
var/mob/player/A
while(A==null)
sleep(10)
for(var/mob/player/target in oview(6,src))
A = target
break
src.dir = pick(NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST)
step_rand(src)


Problem description:

I am making an AI code where the mobs only move when a player enters their range, to save cpu.

The problem is that the movement of the npcs is not smooth or natural. The movement_state of icon isn't even showing up. The mob is "jumping" from one location to another as if it were just teleporting. I tried to change step_size values in step_rand (), but without success.

How to make mobs walk using his movement_state?

Thanks for help!


You have slipped into pixel movement mode. You cannot set step sizes to anything that is not the icon size of the world and still use gliding behavior. You want glide_size, not step-size.
In response to Ter13
Ter13 wrote:
You have slipped into pixel movement mode. You cannot set step sizes to anything that is not the icon size of the world and still use gliding behavior. You want glide_size, not step-size.

Then, in this case, is it better to use walk_rand() ?
I'm not sure I understand
Something in your world is off-grid or has a non-tile step size, and your entire world thinks it is in pixel movement mode now. You've gotta find what's causing that to fix this issue. The problem you are seeing is what happens when the world is set to pixel movement mode rather than tile movement mode.
Best response
client/verb/findliars()
for(var/atom/movable/o in world)
if(o.bound_width%TILE_WIDTH||o.bound_height%TILE_HEIGHT||o.bound_x!=0||o.bound_y!=0||o.step_x!=0||o.step_y!=0||step_size!=TILE_WIDTH)
world.log << "[o.type] @ [o.x]:[o.step_x],[o.y]:[o.step_y],[o.z] : [o.bounds] -&gt; [o.step_size]"


Here's a little verb I wrote in the DreamCrafters discord to help someone else find the same problem. This will tell you why your world is dumping into pixel movement mode.

BYOND currently has very strict rules for defining tile or pixel movement. It is very inconvenient for developers, but once you understand the rules for keeping pixel/tile modes separate, either works fine.

You will need to define TILE_WIDTH and TILE_HEIGHT to be the icon-width and icon-height of tiles in your game for this verb to be useful to you.
In response to Ter13
Ter13 wrote:
Something in your world is off-grid or has a non-tile step size, and your entire world thinks it is in pixel movement mode now. You've gotta find what's causing that to fix this issue. The problem you are seeing is what happens when the world is set to pixel movement mode rather than tile movement mode.

Edit: Only now have I seen your answer with the code. Thank you! The problem is really objects on the map.

Edit2: Can anyone join that discord?

If these objects are the cause of the problem is the only solution to have a natural movement of NPCs is removing all bound and step_size configuration in the world? Or is there a way to adjust the movement in the AI () so that it works as well as the clients do?

Thanks for taking the time to respond and help me!