Jump to content

[HELP] My bullet no follow the good direction


bluecake
 Share

Recommended Posts

Hello,

Today, i have problem... I would like when i "myweapon.fire();" my bullet follow the good direction according to the position of my character.

Problem in movie:

https://i.gyazo.com/d5d4828c9dbdeac86dd0df08fb0f59e8.mp4

 

My weapon source code: (in create)

characterlaser = game.add.weapon(3, 'laser');
characterlaser.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
characterlaser.bulletSpeed = 400;
characterlaser.fireRate = 60;
    
characterlaser.trackSprite(character, 0, 0, true);

When i fire: (in update)

if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
        {
            character.x -= 2;
            character.play('marcheagauche');
            
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
        {
            character.x += 2;
            character.play('marcheadroite');
            
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.UP))
        {
            character.y -= 2;
            character.play('marcheenhaut');
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
        {
            character.y += 2;
            character.play('marcheenbas');
        }
    else if(game.input.keyboard.isDown(32))
        {
            characterlaser.fire();
        }

 

Thank you very much in all those who will come to help me ! :D

Link to comment
Share on other sites

9 hours ago, DanielKlava said:

Hello!

You need to set the "fireAngle" of the weapon object.

For example:


this.weapon.fireAngle = Phaser.ANGLE_RIGHT;

 

Thanks Daniel, but not working, here is my code:

if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
        {
            character.x -= 2;
            character.play('marcheagauche');
            characterlaser.fireAngle = Phaser.ANGLE_LEFT;
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
        {
            character.x += 2;
            character.play('marcheadroite');
            characterlaser.fireAngle = Phaser.ANGLE_RIGHT;
            
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.UP))
        {
            character.y -= 2;
            character.play('marcheenhaut');
            characterlaser.fireAngle = Phaser.ANGLE_UP;
        }
    else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
        {
            character.y += 2;
            character.play('marcheenbas');
            characterlaser.fireAngle = Phaser.ANGLE_DOWN;
        }

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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