Jump to content

auto shot the bullet to locked sprite


scofieldly
 Share

Recommended Posts

This is very rough, but you will want something like this. The lock function will fire when you shoot a bullet setting a variable to false. In your move / update function, check against this value to stop moving it the sprite is locked.

A timer is created for 2 seconds, which on completion will trigger the unlock function, releasing the character. You could go a step further and change the timer to an event callback for the shooting animation, but that's optional. Hope this helps!

shootBullet() {
    this.lock();
    let bullet = new Bullet(x,y,texture); // instantiation of bullet class
    this.game.time.events.add(Phaser.Timer.SECOND * 2, this.unlock, this);
}

lock() {
    this.locked = true;
}

unlock() {
    this.locked = false;
}

move() {
    if(!this.locked) {
        ... // move your char here if not locked
    }
}

 

Link to comment
Share on other sites

12 hours ago, megmut said:

This is very rough, but you will want something like this. The lock function will fire when you shoot a bullet setting a variable to false. In your move / update function, check against this value to stop moving it the sprite is locked.

A timer is created for 2 seconds, which on completion will trigger the unlock function, releasing the character. You could go a step further and change the timer to an event callback for the shooting animation, but that's optional. Hope this helps!

shootBullet() {
    this.lock();
    let bullet = new Bullet(x,y,texture); // instantiation of bullet class
    this.game.time.events.add(Phaser.Timer.SECOND * 2, this.unlock, this);
}

lock() {
    this.locked = true;
}

unlock() {
    this.locked = false;
}

move() {
    if(!this.locked) {
        ... // move your char here if not locked
    }
}

hi megmut,

thanks for your reply, sorry for my misunderstanding explanation, I did not mean when the bullet collide the target will lock the target. I mean the target will keep moving and the gun will adjust the angle to aim the target and keep shotting. do you have any idea about this feature, thanks.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...