关于设计游戏跟踪弹的实现

  • Creator 版本:

  • 目标平台:

  • 详细报错信息,包含调用堆栈:

  • 重现方式:

  • 之前哪个版本是正常的 :

  • 手机型号 :

  • 手机浏览器 :

  • 编辑器操作系统 :

  • 编辑器之前是否有其它报错 :

  • 出现概率:

  • 额外线索:

楼主是想要这种效果吗

1赞

你好,请问这种效果是怎么实现的?可以分享一下吗

他这个是跟踪算法 并计算偏转角度:7:

1赞

很简单 在update里面实时计算两个物体向量的相差角度 让子弹移动到目标位置就好了 player节点代表目标 Bullet节点代表子弹

const { ccclass, property } = cc._decorator;

@ccclass
export default class BulletTrack extends cc.Component {

@property(cc.Node)
Player: cc.Node = null;
@property(cc.Node)
Bullet: cc.Node = null;
@property
bulletSpeed: number = 200;//子弹速度
// LIFE-CYCLE CALLBACKS:
private isbegin: boolean = true
// onLoad () {}

start() {
    cc.tween(this.Player)
        .to(2, { position: cc.v2(-300, 0) })
        .to(2, { position: cc.v2(0, -600) })
        .start()
}

update(dt) {
    let posplayer = this.Player.position
    let posbullet = this.Bullet.position
 
    let dis = posplayer.sub(posbullet).normalize()

    let xx = this.bulletSpeed * dis.x
    let yy = this.bulletSpeed * dis.y
 
    let sx = xx * dt
    let sy = yy * dt

   
    this.Bullet.x += sx
    this.Bullet.y += sy

  
    let r = Math.atan2(dis.y, dis.x);
    let degree = r * 180 / (Math.PI);
    degree = 360 - degree + 90;
    // this.Bullet.rotation = degree;
    this.Bullet.angle = -degree;

    let rect = this.Player.getBoundingBox();
    let bool = rect.contains(this.Bullet.position);
    if (bool) {
        this.Bullet.active = false
    }


    // this.Bullet.position 
}

}

4赞

赞,可以说很详细了

游戏人工智能编程精粹

跟踪弹 mark

跟踪mark