命令百科

effect · set_entity_movement

Definition

  • Supported scope:any
  • Supported target:any

Description

sets the position & rotation of an existing entity using two coordinates
set_entity_movement = {
  id = 123 # id of entity 
  start = { 
    # position can be set using following 
    x = 42 
    y = 21 
    province = 123 
    state = 42 
    z = 3 #if wanted you can specify a z to shift height of the entity
  } 
  target = { 
    # position can be set using following 
    x = 42 
    y = 21 
    province = 123 
    state = 42 
    z = 3 #if wanted you can specify a z to shift height of the entity
  } 
  ratio = 0.5 # a ratio in between 0 - 1. the entity is positioned in between start & target position using this ratio 
  rotation = 1.2 # angle in radio, entity is rotated using the direction and this angle is added after that 
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

set_entity_movement 常用于剧情动画 mod 中,让地图上的自定义实体(飞机、舰船、车辆模型等)沿着指定路径做插值位移,配合事件链逐帧推进可实现过场动画效果。例如在一个展示舰队移动的剧情事件中,通过不断改变 ratio 值来模拟实体从出发港口滑向目标海域:

# 在某个事件的 immediate 块中,让实体移动到起点与终点的中间位置
set_entity_movement = {
    id = 101
    start = {
        province = 11620  # 出发港口所在省份
    }
    target = {
        province = 11634  # 目标海域省份
    }
    ratio = 0.5           # 当前停在路途中间
    rotation = 1.57       # 朝向调整为大致向东(弧度)
}

配合关系

  • [create_entity](/wiki/effect/create_entity) — 实体必须先被创建才能通过本命令移动,二者通常配合出现在同一事件链的不同阶段。
  • [set_entity_rotation](/wiki/effect/set_entity_rotation) — 若只需精确调整朝向而不做位移插值,可与本命令分工;也可在移动后用它做最终朝向校正。
  • [set_entity_animation](/wiki/effect/set_entity_animation) — 移动过程中往往需要同步切换实体的行进动画状态,与本命令同步调用可保证视觉一致性。
  • [destroy_entity](/wiki/effect/destroy_entity) — 动画结束后清理不再需要的实体,与本命令构成"创建→移动→销毁"的完整生命周期。

常见坑

  1. ratio 超出 0–1 范围不会报错但行为未定义:新手有时用变量动态传入 ratio,若变量因累加超过 1.0,实体会被插值到 target 之外的位置,导致模型凭空出现在地图边缘。务必在赋值前用 [clamp_variable](/wiki/effect/clamp_variable)[clamp_temp_variable](/wiki/effect/clamp_temp_variable) 将变量限制在合法区间。
  2. idcreate_entity 的 id 必须严格对应:如果引用了一个尚未创建或已被 destroy_entity 销毁的实体 id,游戏不会崩溃但命令会静默失效,排查时极难发现,建议在同一文件中用注释明确标注每个 id 的生命周期。