42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
TestMover - 移动脚本
|
|
"""
|
|
|
|
from core.script_system import ScriptBase
|
|
|
|
class Testmover(ScriptBase):
|
|
"""移动脚本类"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.speed = 5.0 # 移动速度
|
|
self.direction = [1, 0, 0] # 移动方向
|
|
|
|
def start(self):
|
|
"""脚本开始时调用"""
|
|
self.log("移动脚本开始运行!")
|
|
|
|
def update(self, dt):
|
|
"""每帧更新"""
|
|
if self.transform:
|
|
# 计算移动偏移
|
|
offset_x = self.direction[0] * self.speed * dt
|
|
offset_y = self.direction[1] * self.speed * dt
|
|
offset_z = self.direction[2] * self.speed * dt
|
|
|
|
# 更新位置
|
|
current_pos = self.transform.getPos()
|
|
new_pos = (
|
|
current_pos.x + offset_x,
|
|
current_pos.y + offset_y,
|
|
current_pos.z + offset_z
|
|
)
|
|
self.transform.setPos(*new_pos)
|
|
|
|
def on_destroy(self):
|
|
"""脚本销毁时调用"""
|
|
self.log("移动脚本被销毁")
|