MobEntity¶
Inherits from: LivingEntity
Represents a mobile entity within the game, inheriting from LivingEntity and adding movement-related attributes and functions.
Fields¶
followingPath: boolean — Read-Only¶
Indicates whether this entity is currently following a path.
Methods¶
startFollowPathTo(target: Vec3, targetRadius?: number, searchRange?: number, speed?: number) → ok: boolean¶
Searches for the shortest path to the given position and moves this entity along the path if one is found.
The followingPath property will be true while the entity is moving and will become false once it reaches the destination or if the path is blocked for too long.
Calling this function removes the entity's own AI (wandering, fleeing, targeting) permanently, so the entity stands still once it has finished the path.
If the target lies beyond searchRange or cannot be reached, the entity walks as close as it can get and then stops; the function still returns true in that case.
Example
local pig = spell:summon("pig")
local waypoint = pig.pos + Vec3(0, 0, 10)
local ok = pig:startFollowPathTo(waypoint, 0, 100, 1)
if not ok then
error("No path found to waypoint.")
end
while pig.followingPath do
sleep(20)
end
if (waypoint - pig.pos):magnitude() > 1 then
pig:stopFollowPath()
end
Parameters
- target: Vec3 — The position to move toward.
- targetRadius?: number — The distance (in blocks) at which the target counts as reached. Must be an integer. Defaults to 1.
- searchRange?: number — The maximum path length (in blocks) to search. Must be an integer. Defaults to 50.
- speed?: number — The speed modifier at which the entity moves along the path. Defaults to 1.
Returns
- ok: boolean —
trueif movement starts;falseif no path could be computed.
stopFollowPath()¶
Stops this entity's current movement immediately.