Skip to content

刚体 ​

AddForce ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    对自定义刚体的质心施加全局坐标力;数值单位由mode决定,对运动学刚体无效

  • 参数

    参数名
    数据类型
    说明
    dirtuple(float,float,float)全局坐标输入向量:eFORCE为力(N),eIMPULSE为冲量(N·s),eVELOCITY_CHANGE为速度变化(m/s),eACCELERATION为加速度(m/s²)
    modeintPxForceMode枚举:eFORCE=0、eIMPULSE=1、eVELOCITY_CHANGE=2、eACCELERATION=3
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxForceMode
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 添加一个向上的速度
comp.AddForce((0,1,0), PxForceMode.eVELOCITY_CHANGE)

AddForceAtPos ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    对自定义刚体的指定位置添加力,对运动学刚体无效

  • 参数

    参数名
    数据类型
    说明
    forcetuple(float,float,float)在全局坐标系中定义的力/冲量
    modeintPxForceMode枚举,施加力/冲量时使用的模式
    postuple(float,float,float)在全局坐标系中定义的力/冲量作用点位置
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxForceMode
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 添加一个向上的速度
comp.AddForceAtPos((0,1,0), PxForceMode.eVELOCITY_CHANGE, (0,81,0))

AddForceAtPosLocal ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    对自定义刚体的指定位置添加力,对运动学刚体无效

  • 参数

    参数名
    数据类型
    说明
    forcetuple(float,float,float)在全局坐标系中定义的力/冲量
    modeintPxForceMode枚举,施加力/冲量时使用的模式
    postuple(float,float,float)在局部坐标系中定义的力/冲量作用点偏移
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxForceMode
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 对实体左侧位置添加一个向前的力
comp.AddForceAtPosLocal((0,0,1000), PxForceMode.eFORCE, (1,0,0))

AddTorque ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    对自定义刚体添加扭矩,对运动学刚体无效

  • 参数

    参数名
    数据类型
    说明
    torquetuple(float,float,float)在全局坐标系中定义的扭矩
    modeintPxForceMode枚举,施加力/冲量时使用的模式
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxForceMode
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.AddTorque((0,5000,0), PxForceMode.eFORCE)

AddTorqueLocal ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    在自定义刚体本地坐标系中添加扭矩,对运动学刚体无效。X轴为Roll(滚转),Y轴为Yaw(偏航),Z轴为Pitch(俯仰)

  • 参数

    参数名
    数据类型
    说明
    torquetuple(float,float,float)在刚体本地坐标系中定义的扭矩
    modeintPxForceMode枚举,施加力/冲量时使用的模式
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxForceMode
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.AddTorqueLocal((100,0,0), PxForceMode.eIMPULSE)

CreatePxActor ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    给实体创建自定义刚体

  • 参数

    无

  • 返回值

    数据类型
    说明
    bool是否成功
  • 备注

    • 只能在AddEntityServerEvent事件中使用,不存档
    • 只能对自定义生物使用,不支持玩家与原版实体。自定义生物需移除minecraft:physics等原生物理组件,并且使用SetBlockControlAi关闭ai
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.CreatePxActor()

GetActorFlags ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取 actor 当前 ActorFlags(诊断接口,bit1=eDISABLE_GRAVITY,bit2=eSEND_SLEEP_NOTIFIES,bit3=eDISABLE_SIMULATION)

  • 参数

    无

  • 返回值

    数据类型
    说明
    intActor 标记;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetActorFlags()

GetAngularVelocity ​

服务端客户端

服务端接口 ​

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取自定义刚体的角速度

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float)角速度(rad/s);非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetAngularVelocity()

客户端接口 ​

method in mod.client.component.physxCompClient.PhysxComponentClient

  • 描述

    获取自定义刚体在世界坐标系下的角速度

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float)角速度(rad/s),非自定义刚体返回None
  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetAngularVelocity()

GetLinearVelocity ​

服务端客户端

服务端接口 ​

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取自定义刚体的线速度(world space)

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float)线速度;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetLinearVelocity()

客户端接口 ​

method in mod.client.component.physxCompClient.PhysxComponentClient

  • 描述

    获取自定义刚体在世界坐标系下的线速度

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float)线速度(blocks/s),非自定义刚体返回None
  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetLinearVelocity()

GetMass ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取自定义刚体的质量(PhysX 内部 mass,由 density+体积合成)

  • 参数

    无

  • 返回值

    数据类型
    说明
    float质量;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetMass()

GetMassSpaceInertiaTensor ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取刚体的惯性张量对角线分量

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float)惯性张量(Ix,Iy,Iz);非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetMassSpaceInertiaTensor()

GetQuaternion ​

服务端客户端

服务端接口 ​

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取自定义刚体的四元数旋转

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float,float)四元数
  • 备注

    • 非自定义刚体返回(0,0,0,1)
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetQuaternion()

客户端接口 ​

method in mod.client.component.physxCompClient.PhysxComponentClient

  • 描述

    获取自定义刚体的四元数旋转

  • 参数

    无

  • 返回值

    数据类型
    说明
    tuple(float,float,float,float)四元数
  • 备注

    • 非自定义刚体返回(0,0,0,1)
  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetQuaternion()

GetRigidBodyFlags ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取刚体当前 RigidBodyFlags(诊断接口,bit0=eKINEMATIC)

  • 参数

    无

  • 返回值

    数据类型
    说明
    int刚体标记;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetRigidBodyFlags()

GetRigidDynamicLockFlags ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    获取动态刚体当前 RigidDynamicLockFlags(诊断接口,bit0-2=Linear XYZ lock,bit3-5=Angular XYZ lock)

  • 参数

    无

  • 返回值

    数据类型
    说明
    int动态刚体锁定标记;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.GetRigidDynamicLockFlags()

IsDefaultPxActor ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    是否为引擎默认创建的 PxActor(诊断接口,True 表示 mod CreatePxActor 实际是 no-op)

  • 参数

    无

  • 返回值

    数据类型
    说明
    bool是否为默认 PxActor;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.IsDefaultPxActor()

IsSleeping ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    查询自定义刚体是否处于休眠状态

  • 参数

    无

  • 返回值

    数据类型
    说明
    bool是否休眠;非自定义刚体时返回None
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
print comp.IsSleeping()

PutToSleep ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    强制刚体进入休眠

  • 参数

    无

  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.PutToSleep()

SetActorFlag ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置物理实体的行为开关

  • 参数

    参数名
    数据类型
    说明
    flagintPxActorFlag枚举
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxActorFlag
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 不受重力
comp.SetActorFlag(PxActorFlag.eDISABLE_GRAVITY, True)

SetAngularDamping ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置动态刚体的角阻尼,值越大角速度衰减越快

  • 参数

    参数名
    数据类型
    说明
    dampingfloat角阻尼,必须大于等于0
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetAngularDamping(1.0) # 角速度衰减系数

SetAngularVelocity ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的角速度,对运动学刚体无效

  • 参数

    参数名
    数据类型
    说明
    velocitytuple(float,float,float)角速度(rad/s)
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetAngularVelocity((0.0, 3.14, 0.0)) # 绕世界 Y 轴旋转

SetCMassLocalPose ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置质心相对于actor原点的偏移,用于手动调整重心

  • 参数

    参数名
    数据类型
    说明
    postuple(float,float,float)质心在局部坐标中的位置
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetCMassLocalPose((0.0, -0.5, 0.0)) # 将重心下移半格

SetGlobalPose ​

服务端客户端

服务端接口 ​

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的变换(直接瞬移)

  • 参数

    参数名
    数据类型
    说明
    postuple(float,float,float)或None目标位置,None表示位置不变
    rottuple(float,float,float,float)或None目标旋转,用四元数表示,None表示旋转不变
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 瞬移到0,80,0,旋转不变
comp.SetGlobalPose((0,80,0), None)

客户端接口 ​

method in mod.client.component.physxCompClient.PhysxComponentClient

  • 描述

    设置客户端本地自定义刚体的变换(直接瞬移)

  • 参数

    参数名
    数据类型
    说明
    postuple(float,float,float)或None目标位置,None表示位置不变
    rottuple(float,float,float,float)或None目标旋转,用四元数表示,None表示旋转不变
  • 返回值

    数据类型
    说明
    bool是否成功
  • 备注

    • 仅更新客户端本地 PhysX 副本,可用于视觉预测;不会同步到服务端权威刚体

SetKinematicTarget ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置运动学刚体的目标变换,仅对开启了PxRigidBodyFlag.eKINEMATIC的自定义刚体生效

  • 参数

    参数名
    数据类型
    说明
    postuple(float,float,float)或None目标位置,None表示位置不变
    rottuple(float,float,float,float)或None目标旋转,用四元数表示,None表示旋转不变
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 位置移动到0,80,0,旋转不变
comp.SetKinematicTarget((0,80,0), None)

SetLinearDamping ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置动态刚体的线性阻尼,值越大线速度衰减越快

  • 参数

    参数名
    数据类型
    说明
    dampingfloat线性阻尼,必须大于等于0
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetLinearDamping(0.5) # 线速度衰减系数

SetLinearVelocity ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的线速度(world space),仅对PxRigidDynamic生效

  • 参数

    参数名
    数据类型
    说明
    velocitytuple(float,float,float)目标线速度(vx,vy,vz)
  • 返回值

    数据类型
    说明
    bool成功返回True,失败返回False
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetLinearVelocity((0.0, 0.0, 8.0)) # 立即设为向 +Z 匀速运动

SetMass ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置动态刚体质量

  • 参数

    参数名
    数据类型
    说明
    massfloat目标质量,必须大于0
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetMass(20.0)

SetMaxAngularVelocity ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的最大角速度,防止碰撞后疯转

  • 参数

    参数名
    数据类型
    说明
    maxVelfloat最大角速度(rad/s),必须大于0,默认100
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetMaxAngularVelocity(20.0) # 限制为 20 rad/s

SetMaxLinearVelocity ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的最大线速度,防止物体飞出天际

  • 参数

    参数名
    数据类型
    说明
    maxVelfloat最大线速度(m/s),默认无限
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetMaxLinearVelocity(30.0)

SetRigidBodyFlag ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的行为开关

  • 参数

    参数名
    数据类型
    说明
    flagintPxRigidBodyFlag枚举
    valbool开关
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxRigidBodyFlag
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.SetRigidBodyFlag(PxRigidBodyFlag.eKINEMATIC, True) # 设置为运动学刚体

SetRigidDynamicLockFlags ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    设置自定义刚体的约束

  • 参数

    参数名
    数据类型
    说明
    flagintPxRigidDynamicLockFlag枚举
  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
from common.minecraftEnum import PxRigidDynamicLockFlag
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
# 锁定xyz轴旋转
comp.SetRigidDynamicLockFlags(PxRigidDynamicLockFlag.eLOCK_ANGULAR_X | PxRigidDynamicLockFlag.eLOCK_ANGULAR_Y | PxRigidDynamicLockFlag.eLOCK_ANGULAR_Z)

WakeUp ​

服务端

method in mod.server.component.physxCompServer.PhysxComponentServer

  • 描述

    唤醒休眠中的刚体

  • 参数

    无

  • 返回值

    数据类型
    说明
    bool是否成功
  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePhysx(entityId)
comp.WakeUp()