How do I move characters that don't have a player (and never will)?
Posted: Wed Sep 14, 2022 3:24 am
I'm trying to create NPCs for a scenario I'm working on but I can't seem to figure out how to make the created entity of the character prototype move around in the way a player/biter would. Meaning walk around navigating around obstacles VS teleport() to instantly reach the desired destination.
Take the snippet of code at the bottom of this post. I create a character then tell it to move to {50,0} and (hopefully) do whatever path-finding might be necessary to reach that location. Instead of these results I get "Error: Entity is not unit."
Is there any way to accomplish what I'm wanting? I've looked around the API docs but this is one of those times they confuse me because of how overloaded LuaEntity is. Even doing `/c log(game.player.selected.help()` just returns the same info as the API docs and not just the methods/properties that are valid for an entity of the character prototype (which is what I had under my mouse for the "selected" entity in that command).
Preferably without having to do modifications in the data stage but I can go that route if I must.
TL;DR:
I'd like to know how to do these "player" type actions on a entity of the character prototype but I'm too inexperienced to figure it out.
Move a "NPC" (really a character) to LuaPosition or LuaEntity.
Look at LuaPosition or LuaEntity (kinda like when a player mouses over an entity and the player's character looks in that direction.
Shoot at LuaPosition or LuaEntity.
Take the snippet of code at the bottom of this post. I create a character then tell it to move to {50,0} and (hopefully) do whatever path-finding might be necessary to reach that location. Instead of these results I get "Error: Entity is not unit."
Is there any way to accomplish what I'm wanting? I've looked around the API docs but this is one of those times they confuse me because of how overloaded LuaEntity is. Even doing `/c log(game.player.selected.help()` just returns the same info as the API docs and not just the methods/properties that are valid for an entity of the character prototype (which is what I had under my mouse for the "selected" entity in that command).
Preferably without having to do modifications in the data stage but I can go that route if I must.
Code: Select all
local e = game.surfaces.nauvis.create_entity({
name = "character",
position = {0,0}
})
e.set_command({
type = defines.command.go_to_location,
destination = {50,0},
distraction = defines.distraction.none
})
I'd like to know how to do these "player" type actions on a entity of the character prototype but I'm too inexperienced to figure it out.
Move a "NPC" (really a character) to LuaPosition or LuaEntity.
Look at LuaPosition or LuaEntity (kinda like when a player mouses over an entity and the player's character looks in that direction.
Shoot at LuaPosition or LuaEntity.