将以下代码黏贴到链接(https://layaair.ldc.layabox.com/demo2/?language=zh&category=3d&group=Physics3D&name=PhysicsWorld_BaseCollider)执行代码可以发现移动父级,子物体本地位置异常。
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();