Pixijs: Arc Bullet Effect

82 Views Asked by At

I'm learning game making on Pixijs and am having some problems.

Currently, the projectile has followed an arc trajectory but has the problem that it is in the same position.

For example, a for loop has 10 bullets, then the bullets are in turn followed each other by a distance (eg about 10px).

Here is my current code. If you have an answer, please reply to me.

Note:
  1. donDanh.hieuung : Number of bullets
  2. bullet: container of [i]
  3. mucTieu.x, .y : Target to
  4. donDanh.x, .y : Bullet starting point
for (let i = 0; i < donDanh.hieuung; i++) {
    let bullet = addnewskill.getChildByName(element.id + "_" + i);
    if (bullet.time % 5 == 0) {
      bullet.texture =
        PIXI.utils.TextureCache[
          getNameSkill(
            element.name,
            element.level,
            follow.src[bullet.start]
          )
        ];

      bullet.start++;
      if (bullet.start + 1 > soKhung) {
        bullet.start = 0;
      }
    }
    bullet.time++;

  let dx = mucTieu.x - donDanh.x;
  let dy = mucTieu.y - donDanh.y;
  let distance = Math.sqrt(dx * dx + dy * dy);
  let angle = Math.atan2(dy, dx);
  let midX = (donDanh.x + mucTieu.x) / 2;
  let midY = (donDanh.y + mucTieu.y) / 2 - distance / 4;

  let bulletSpeed = 5; // speed of bullet
  let timeElapsed = bullet.time + i * 2; // time elapsed since bullet was fired
  let t = timeElapsed / (distance / bulletSpeed); // 
  let x = (1 - t) * (1 - t) * donDanh.x + 2 * (1 - t) * t * midX + t * t * mucTieu.x; // Tọa độ x của điểm trên đường cong tại thời điểm tương đối của viên đạn
  let y = (1 - t) * (1 - t) * donDanh.y + 2 * (1 - t) * t * midY + t * t * mucTieu.y +  0; // Tọa độ y của điểm trên đường cong tại thời điểm tương đối của viên đạn


  bullet.x = x ;
  bullet.y = y;

}

Thank you !

enter image description here

This is Program I want:

This is Program I want

0

There are 0 best solutions below