How to destroy a moving bullet?

0 favourites
  • 10 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • Hi guys, I'm trying to whenever i touches the screen, the bullet will be spawn from the player, and the bullet will be destroyed on where I touch. To do that, I tried

    Touch, on any touch start

    • Player spawn bullet
    • set x (instance variable) to Touch.X
    • set y (instance variable) to Touch.Y
    • Bullet set angle towards (Touch.X, Touch.Y)

    Sub-event

    • Bullet X = x and Bullet Y = y, destroy bullet

    Below is my capx file

    https://www.dropbox.com/s/56io2ckgi36qf ... .capx?dl=0

  • Kind of obvious (but I don't blame your possible inexperience) but did you try adding on tap to the sub-event?

  • I'm sorry, what do you mean "on tap"?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The simplest way to do this is on any touch create a different invisible object for detection at touch.x, touch.y and destroy sprite2 when overlapping the created object.

  • It's in the actions for Touch controls. It's a trigger condition for Touch that says "On tap"

  • Oh my! How could I not think of that?! Thanks alot for helping out!

  • If I understand correctly the issue you mentioned at first, you want the bullet to be destroyed when it reaches a certain destination, right ?

    The issue there is that the event doing so is a sub-event of the spawning of the bullet (which cannot logically work if the destination is on the other side of the screen).

    What you want to do is separate that event, and also define a range instead of an absolute destination (most of the time, your bullet won't be going through the EXACT X and Y position).

    Lastly you want the bullet to "remember " those coordinates.

    So in the end you would have something like that instead (where destX and destY are instance variables of Sprite2 :

  • Kyatric I had tried your method, and it works, thanks alot! By the way, I also found another way to do so by using the turret behaviour.

    System Every Tick

    • Player : Add Turret target sprite1

    On any touch start

    • System : Create object sprite1 on layer 0 at (Touch.X, Touch.Y)

    On any touch end

    • Sprite1 : Destroy
  • The simplest way to do this is on any touch create a different invisible object for detection at touch.x, touch.y and destroy sprite2 when overlapping the created object.

    niiiiiiice! i like the way you think!

  • Bullet behavior has a setting for distance traveled, I believe. So:

    Bullet, compare distance traveled, if > (start.x, start.y, finish.x, finish.y) then destroy bullet

    Of course those are just placeholder terms. If the player doesn't move you can use player.x & player.y, but if he does move either add instance variables for startX & startY, or just create a 'distance' variable and on created set distance to distance(player.x, player.y, touch.x, touch.y).

    This is a better solution than creating invisible sprites as doesn't create unnecessary sprites, doesn't' have to check for the collision, and doesn't have the chance of (somehow) not hitting the invisible sprite—or hitting an invisible sprite meant for a different bullet.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)