Jump to content

noob question about collision


Aperosuz
 Share

Recommended Posts

Hi everybody,

I am really sorry but i have a problem i think very easy for you, but i will complicated the things because i have make my code very disgusting ...

 

So I have 1 group with cannon in create and a function to make appear their with random coordinate, and when this function run i create my sprite with bullet to shoot my player. This part is disgusting but she work.

  function launchRWeapon() {        var enemy = Rweapon.getFirstExists(false);    randwidth = game.rnd.integerInRange(35, 975);    randheight = game.rnd.integerInRange(35, 615);    while(randwidth > 350 && randwidth < 670 && randheight > 160 && randheight < 480)    {      randwidth = game.rnd.integerInRange(35, 975);         randheight = game.rnd.integerInRange(35, 615);    }    if(!enemy){      nextlevel();    }    else    {      enemy.reset(randwidth, randheight);      enemy.rotation = game.physics.arcade.angleBetween(enemy, boat);      bull = game.add.sprite(enemy.x, enemy.y, 'bullet');      boat.anchor.setTo(0.5, 0.5);      game.physics.arcade.enable(bull);      bull.body.bounce.set(1);      power = 300;      //  Our launch trajectory is based on the angle of the turret and the power      game.physics.arcade.velocityFromRotation(enemy.rotation, power, bull.body.velocity);      if(delay > delaymin)      {        delay = delay - 50;      }      RweaponLaunchTimer = game.time.events.add(delay, launchRWeapon);    }      }

After this, my player have a shield to protect him (the shield turn around my player with the right and left button) and send back the bullet but sometimes the bullet are deflect at a place where my shield isn't (for example my shield is at left and the bullet come from right and it s deflect before to could touch my player, like the shield is here). And often, my bullet just cross my shield and don't make anything ....

 

here it's my shield (just a red line):

hield = game.add.sprite(505 , 325 , '1');    shield.anchor.setTo(0.5, 8);     game.physics.arcade.enable(shield);

here it's my overlap in update: (I have put a var bull; between my preload and create function)

game.physics.arcade.overlap(shield, bull, Reditum);

and finally my Reditum function (send back, and it's just a test it's why my angle is fix to -90):

function Reditum(shield, bullet){    game.physics.arcade.velocityFromAngle(-90, 300, bullet.body.velocity);    game.physics.arcade.overlap(Bweapon, bullet, BbackSuccess, null, this);    game.physics.arcade.overlap(Rweapon, bullet, RbackSuccess, null, this);  }

So my question is why my bullet  don't deflect fine on my shield, and if you know how calculate the angle to send back my bullet correctly (if it come from bot left, it need to go on top left).

 

I hope you have understand all of this because this is not my case ^^

 

Thank you very much

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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