Jump to content

[Solved]How to limit the shooting direction of the sprite??

Recommended Posts

I use the following example to get start.


When the arrow's angle  <= 90 and  >= 90, the arrow will stop move and can not shoot to the left!!!!



I use the follow code

function update() {
     if(sprite.angle <= -90 && sprite.angle >= -180){
    } else if(sprite.angle >= 90 && sprite.angle <= 180){
    if(sprite.angle >= -90 && sprite.angle <= 0){

      sprite.angle = -90;  

    } else if(sprite.angle <= 90 && sprite.angle >= 0){
      sprite.angle = 90;  



But  I hope the bullet not shoot to the left, any idea??? Thanks you so much



Here is the jsfiddle link, Thanks


Link to post
Share on other sites
1 hour ago, gauravD said:

You need to add the same angle constraints to bullet firing too.

So instead of firing when the pointer is down,

if (game.input.activePointer.isDown){

you fire when the pointer is down and your sprite follows your angle constraints.

if (game.input.activePointer.isDown && sprite.angle >= -90 && sprite.angle <=90){


Works perfectly!!! You are so awesome!!!Thank you very much and have a nice day!!




Link to post
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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...