新手第一次用cocos,想写一个摄像头跟随主角移动的脚本。但cocos 3.6.1中好像已经没有runAction可以调用了,如图,请问大佬们在cocos 3.x中要怎么对这段代码修改才能实现摄像头跟随主角移动并且碰到边界停止的效果阿
好像连follow也没有了
大概这样呢?
@ccclass('Follow')
export class Follow extends Component {
@property(Node)
private targetNode: Node = null;
@property(Rect)
private scope: Rect = new Rect(0, 0, 5000, 5000);
private moveScope: Rect = null;
protected onLoad(): void {
const camera = this.node.getComponent(Camera);
//这应该用Camera视窗大小,算出真正的移动范围,明天有时间改一下
this.moveScope = new Rect(this.scope);
}
protected update(deltaTime: number): void {
if (!this.targetNode) return;
const worldPosition = this.targetNode.worldPosition;
this.node.setWorldPosition(
math.clamp(worldPosition.x, this.moveScope.x, this.moveScope.x + this.moveScope.width),
math.clamp(worldPosition.y, this.moveScope.y, this.moveScope.y + this.moveScope.height),
this.node.position.z
);
}
}
没测啊 猜的,主要是math.clamp给他限制在范围内就行吧
