setPosition位置不更新是什么原因(新手求救)

用3.0 联系2.x的示例,位置就是无法更新了
update(dt: number) {
if (this.accLeft) {
this.xSpeed -= this.accel * dt;
}
else if (this.accRight) {
this.xSpeed += this.accel * dt;
}

    if (Math.abs(this.xSpeed) > this.maxMoveSpeed) {
        this.xSpeed = this.maxMoveSpeed * this.xSpeed / Math.abs(this.xSpeed);
    }

    this.curPos = this.node.getPosition()
    this.deltaPos = new Vec3(this.xSpeed * dt, 0, 0)
  
    this.curPos = new Vec3((this.curPos.x + this.xSpeed * dt) as number, this.curPos.y, this.curPos.z)

   //curPos的x也在变 ,可是setPosition无效
    this.node.setPosition(this.curPos);
}

求大神们指教

先试着把变动后的this.curPos换个变量名,比如this.nextPos?
然后既然只有一个x方向有变动,3.0版本能否直接用
this.node.position.x += this.xSpeed*dt;

换变量名也不行
直接node.position.x 也不行 :frowning_face:

我去测试了一下,setPosition有效。
update (deltaTime: number) {

    let curPos = this.node.getPosition();

    console.log(curPos);

    let nextPos = new Vec3(curPos.x + 100 * deltaTime, curPos.y, curPos.z)

    console.log(nextPos);

    this.node.setPosition(nextPos);

}

也许是数据的量级设置得不合适?


去掉跳跃动画就可以移动了,这有什么冲突吗

这里的this.dx是什么?

就是0 常值

也许是冲突了。其实我也是新手,感觉最好这两个方向的运动单独分开设置好些

Vec3毕竟是个三维向量,2.4版本的案例其实也是单独分开两个方向的运动轨迹吧?

嗯嗯 其实就是2.4的例子 也是动画处理y 在update里更新x 不知道怎么改

新版3.0是建议多使用position的getter和setter,如果实在需要分别设置position.x,position.y才能解决问题,能用就用吧

嗯嗯 我再查查文档 谢谢