[LayaAir 2.0]timer.loop帧率高于物理帧率移动父级导致子物体本地坐标异常
将以下代码黏贴到链接(https://layaair.ldc.layabox.co ... lider)执行代码可以发现移动父级,子物体本地位置异常。
class PhysicsWorldBaseCollider{
constructor(){
//初始化引擎
Laya3D.init(0, 0);
//设置画布模式
Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
//Laya.stage.frameRate = Laya.Stage.FRAME_SLOW;
Laya.Stat.show();
this.scene = Laya.stage.addChild(new Laya.Scene3D());
Laya.timer.loop(1, this, this.loopfun);
}
loopfun(){
this.lastT = Date.now();
let dis = 1;
if(!this.cubeP){
this.cubeP = this.scene.addChild(new Laya.Sprite3D());
this.cube = this.cubeP.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1)));
let rigidbody = this.cube.addComponent(Laya.Rigidbody3D);
rigidbody.mass = 0.01;
rigidbody.overrideGravity = true;
rigidbody.gravity = new Laya.Vector3();
rigidbody.isTrigger = true;
rigidbody.isKinematic = false;
rigidbody.colliderShape = new Laya.CompoundColliderShape();
this.cube.transform.localPosition = new Laya.Vector3();
}
let pos = this.cubeP.transform.position;
pos.z += dis;
this.cubeP.transform.position = pos;
if(this.cube.transform.localPosition.z != 0)
console.log(this.cube.transform.localPosition.z);
}
}
//激活启动类
new PhysicsWorldBaseCollider();
class PhysicsWorldBaseCollider{
constructor(){
//初始化引擎
Laya3D.init(0, 0);
//设置画布模式
Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
//Laya.stage.frameRate = Laya.Stage.FRAME_SLOW;
Laya.Stat.show();
this.scene = Laya.stage.addChild(new Laya.Scene3D());
Laya.timer.loop(1, this, this.loopfun);
}
loopfun(){
this.lastT = Date.now();
let dis = 1;
if(!this.cubeP){
this.cubeP = this.scene.addChild(new Laya.Sprite3D());
this.cube = this.cubeP.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(1, 1, 1)));
let rigidbody = this.cube.addComponent(Laya.Rigidbody3D);
rigidbody.mass = 0.01;
rigidbody.overrideGravity = true;
rigidbody.gravity = new Laya.Vector3();
rigidbody.isTrigger = true;
rigidbody.isKinematic = false;
rigidbody.colliderShape = new Laya.CompoundColliderShape();
this.cube.transform.localPosition = new Laya.Vector3();
}
let pos = this.cubeP.transform.position;
pos.z += dis;
this.cubeP.transform.position = pos;
if(this.cube.transform.localPosition.z != 0)
console.log(this.cube.transform.localPosition.z);
}
}
//激活启动类
new PhysicsWorldBaseCollider();
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Aar0n
赞同来自: