forked from Rowland/EG
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
旋转脚本 - 让对象持续旋转
|
|
"""
|
|
|
|
from core.script_system import ScriptBase
|
|
|
|
class RotatorScript(ScriptBase):
|
|
"""旋转脚本类"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.rotation_speed_y = 30.0 # Y轴旋转速度 (度/秒)
|
|
self.is_rotating = True # 是否正在旋转
|
|
|
|
def start(self):
|
|
"""脚本开始时调用"""
|
|
self.log("旋转脚本启动!")
|
|
self.log(f"旋转速度: {self.rotation_speed_y}度/秒")
|
|
|
|
def update(self, dt):
|
|
# 检查 gameObject 是否存在且不为空
|
|
if not self.gameObject or self.gameObject.isEmpty():
|
|
print("RotatorScript: gameObject is empty or None, skipping update")
|
|
return
|
|
"""每帧更新"""
|
|
if not self.is_rotating:
|
|
return
|
|
|
|
# 获取当前旋转并应用增量
|
|
current_hpr = self.gameObject.getHpr()
|
|
new_h = current_hpr.getX() + self.rotation_speed_y * dt
|
|
self.gameObject.setHpr(new_h, current_hpr.getY(), current_hpr.getZ())
|
|
|
|
def on_destroy(self):
|
|
"""脚本销毁时调用"""
|
|
self.log("旋转脚本停止") |