[LayaAirIDE 2.0][BUG]刚体约束问题,移动后约束混乱!

import { ui } from "./../ui/layaMaxUI";
/**
 * 本示例采用非脚本的方式实现,而使用继承页面基类,实现页面逻辑。在IDE里面设置场景的Runtime属性即可和场景进行关联
 * 相比脚本方式,继承式页面类,可以直接使用页面定义的属性(通过IDE内var属性定义),比如this.tipLbll,this.scoreLbl,具有代码提示效果
 * 建议:如果是页面级的逻辑,需要频繁访问页面内多个元素,使用继承式写法,如果是独立小模块,功能单一,建议用脚本方式实现,比如子弹脚本。
 */
export default class GameUI extends ui.test.TestSceneUI {
  private newScene:Laya.Scene3D;
  private boxA: Laya.MeshSprite3D;
  constructor() {
    super();
    Laya3D.init(0, 0);
    Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
    Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;
    Laya.Stat.show();
    this.newScene = Laya.stage.addChild(new Laya.Scene3D()) as Laya.Scene3D;
  
    //初始化照相机
    var camera = this.newScene.addChild(new Laya.Camera(0, 0.1, 100)) as Laya.Camera;
    camera.transform.translate(new Laya.Vector3(0, 3, 30));
    
    //方向光
    const directionLight =this.newScene.addChild(new Laya.DirectionLight()) as Laya.DirectionLight;
    directionLight.color = new Laya.Vector3(1, 1, 1);
    //设置平行光的方向
    directionLight.transform.worldMatrix.setForward(new Laya.Vector3(-1.0, -1.0, 1.0));
    
    //平面
    var plane = this.scene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createPlane(40, 40, 40, 40)));
    plane.transform.position = new Laya.Vector3(0, -2.0, 0);
    var planeMat = new Laya.BlinnPhongMaterial();
    Laya.Texture2D.load("res/threeDimen/Physics/grass.png", Laya.Handler.create(this, function (tex) {
      planeMat.albedoTexture = tex;
    }));
    //设置纹理平铺和偏移
    var tilingOffset = planeMat.tilingOffset;
    tilingOffset.setValue(5, 5, 0, 0);
    planeMat.tilingOffset = tilingOffset;
    //设置材质
    plane.meshRenderer.material = planeMat; 
    this.rotateAngularX(); 
    setTimeout(() => {
      this.boxA.transform.position = new Laya.Vector3(1, 3, 0); // 移动一下A, 竟然角度变了?从来没变过A的角度
    }, 2000); 
    // this.rotateAngularX2();
  } 
  rotateAngularX(){
    this.boxA = this.addRigidBodySphere(new Laya.Vector3(0, 3, 0),1);
    let boxARigid = this.boxA.getComponent(Laya.Rigidbody3D); 
    let boxB = this.addRigidBodyBox(new Laya.Vector3(0, 1, 0),1);
    let boxBRigid = boxB.getComponent(Laya.Rigidbody3D);
    
    let configurableConstraint = this.boxA.addComponent(Laya.ConfigurableConstraint); 
    configurableConstraint.setConnectRigidBody(boxARigid,boxBRigid);
    configurableConstraint.anchor = new Laya.Vector3(0, -2, 0);
    configurableConstraint.connectAnchor = new Laya.Vector3(0, 0.5, 0); 
    configurableConstraint.minAngularLimit = new Laya.Vector3(-2, 0,0);
    configurableConstraint.maxAngularLimit = new Laya.Vector3(2, 0,0);
    configurableConstraint.XMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint.YMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint.ZMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint.angularXMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_FREE;
    configurableConstraint.angularYMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint.angularZMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    boxBRigid.angularVelocity = new Laya.Vector3(5, 0, 0);
    
    let boxC = this.addRigidBodySphere(new Laya.Vector3(-3, 3, 0),1);
    boxC.transform.rotate(new Laya.Vector3(0,120,0)); // 只转了C !!!
    let boxCRigid = boxC.getComponent(Laya.Rigidbody3D); 
    let boxD = this.addRigidBodyBox(new Laya.Vector3(-3, 1, 0),1);
    let boxDRigid = boxD.getComponent(Laya.Rigidbody3D);
    
    let configurableConstraint2 = boxC.addComponent(Laya.ConfigurableConstraint); 
    configurableConstraint2.setConnectRigidBody(boxCRigid,boxDRigid);
    configurableConstraint2.anchor = new Laya.Vector3(0, -2, 0);
    configurableConstraint2.connectAnchor = new Laya.Vector3(0, 0.5, 0); 
    configurableConstraint2.minAngularLimit = new Laya.Vector3(-2, 0,0);
    configurableConstraint2.maxAngularLimit = new Laya.Vector3(2, 0,0);
    configurableConstraint2.XMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint2.YMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint2.ZMotion = Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint2.angularXMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_FREE;
    configurableConstraint2.angularYMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    configurableConstraint2.angularZMotion= Laya.ConfigurableConstraint.CONFIG_MOTION_TYPE_LOCKED;
    boxDRigid.angularVelocity = new Laya.Vector3(5, 0, 0);
    
  } 
  addRigidBodyBox(pos, scale){
    var box = this.newScene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createBox(scale, scale, scale))) as Laya.MeshSprite3D;
    box.transform.position = pos;
    var mat = new Laya.BlinnPhongMaterial();
    box.meshRenderer.material = mat;
    var rigidBody = box.addComponent(Laya.Rigidbody3D);
    var boxShape = new Laya.BoxColliderShape(scale, scale, scale);
    rigidBody.colliderShape = boxShape;
    rigidBody.mass = 1;
    return box; 
  }   
  addRigidBodySphere(pos, scale) {
    var sphere = this.newScene.addChild(new Laya.MeshSprite3D(Laya.PrimitiveMesh.createSphere(0.2))) as Laya.MeshSprite3D;
    sphere.transform.position = pos;
    var mat = new Laya.BlinnPhongMaterial();
    mat.albedoColor = new Laya.Vector4(0, 1, 0, 1);
    sphere.meshRenderer.material = mat;
    var rigidBody = sphere.addComponent(Laya.Rigidbody3D);
    var boxShape = new Laya.SphereColliderShape(0.2);
    rigidBody.colliderShape = boxShape;
    rigidBody.isKinematic = true;
    return sphere;  
  } 
}
 就这点代码,引擎组拿去测试一下,希望尽快给反馈!

1.png


2.png

 
已邀请:

赞同来自:

3.png

相同代码,先创建C、D,位置都出问题了

Laya_z

赞同来自:

已经复现所说问题,正在排队处理中

要回复问题请先

商务合作
商务合作