cocos creator子弹朝坦克指向的方向发射,代码如下:
let pos:cc.Vec3 = cc.v3(this.node.position.x,this.node.position.y);
let rad:number =Math.PI * (90 + this.node.angle) / 180;
var dir = cc.v2(Math.cos(rad),Math.sin(rad));
let insX:number = Math.cos(rad)*this.speed;//x增量
let insY:number = Math.sin(rad)*this.speed;//y增量
this.body.linearVelocity = cc.v2(insX, insY);
设置子弹位置的时候不要使用setPosition方法,要使用线性速度,否则当碰撞检测的时候,子弹仍然能穿过墙体.