[LayaAir3]动态添加2d物理引擎shape无效

  let sp = new Laya.Sprite();
  var rig = new Laya.RigidBody();
  //rig.type = "dynamic";
  rig.bullet = true;
  let shape = new Laya.CircleShape2D();
  shape.x = -10;
  shape.y = -10;
  shape.restitution = 1;
  shape.friction = 1;
  shape.radius = 100;
  rig.gravityScale = 0;
  rig.angularDamping = 10000;
  rig.linearVelocity = new Laya.Vector2(10000, 0);
  rig.linearDamping = 1;
  //设置动态添加的Sprite节点的shape无效
  rig.shapes = [shape];
  sp.addComponentInstance(rig);
  this.Sprite.parent.addChild(sp);
  //设置ide中Sprite节点的shape有效
  this.Sprite.getComponent(Laya.RigidBody).shapes = [shape];
已邀请:

LayaAir大为

赞同来自:

新旧两版的碰撞器设置方法不一样,旧版的碰撞器(BoxCollider)是作为一个组件添加到节点上的,新版的碰撞形状(BoxShape2D)是作为一个属性添加到刚体上的,现在版本如果要动态设置shapes就必须把刚体上的applyOwnerColliderComponent属性设为false,否则不会生效,后面如果有改动了我再来回复一下

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作