Limiting Spawn on Continuous KeyDown

This forum is currently in read-only mode.
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hey everyone, first comer here with some troubles (What's new right?)

    Me and some graduate friends of mine from College are broadening our knowledge of different engines and decided to give Construct a try (Experienced in UDK, Unity, Source, & Flash). I haven't really coded anything in a good while as I focus on documentation, textures, and level design so this is helping me get a hang of it again. Enough of my backstory though and onto my problem.

    We are currently working on a top down Metroid game seeing as there hasn't been many attempts at it (1 in GM). We have everything down more or less minus the coding on this project and I have already hit my first stump. I know how to fix it logically and could probably do it with actual code but as I'm not all experienced with Construct, I'm stuck.

    Basically I am trying to get the Charge beam to work with a held Right Click. At the same time I need to keep the shot sprite on the image point as Samus rotates (360 movement.) What is happening though is the sprite just keeps being generated. I have been able to get each to work on their own, but not at the same time.

    My best attempt was this:

    Right Click pressed DOWN

    Trigger Once

    ->Spawn Bullet samus (@Cannon Point)

    ->Set Bullet Speed 0 (Keeps bullet still)

    Right Click RELEASE

    ->Set Bullet Speed 500 (Normal shot speed)

    That stops the bullet obviously, then I try to use an "Always Tick" for the setting of the cannon, but then that just drags all the bullets to the Cannon (which I can probably use for other things.) On top of that, when I can keep the bullet there, it doesn't want to shoot in the direction Samus is facing. I think I know what to do to fix the directional issue but help would be appreciated regardless.


    I am using the Magic Cam plugin for camera if that matters. WASD to move around, Samus tracks mouse to aim, Left Click is single shot, Right Click is meant for Charge shot. File is used mainly for testing purposes, the problematic area is bookmarked.

    Thanks in advance!

  • Without seeing the .cap, I'd say You're just missing this:

    Right Click pressed DOWN

    Trigger Once:

    ->Spawn Bullet samus (@Cannon Point)

    ->Set Bullet Speed 0 (Keeps bullet still)


    ->Bullet: Set Position to another Object('Samus', 'CannonPoint')

    ->Bullet: Set Angle = Samus.Angle

  • I tried this, and it would cause the bullets on the screen to gravitate back onto the Cannon if the player hit Right Click too fast. Also it seemed to me like if I used Trigger Once along with an Always statement, that the bullet would only attach once and the Always statement would be ignored. I want to say I tried this but I will try it again.

    EDIT: Yea just tried it and it only tracks to the cannon once. Seems like the Trigger once is called and then nothing else in that event runs until it's called again.

  • Okay to solve that, You just need to filter the "picked" instances of the Bullet Sprite.

    You could add an Event in the Always SUB-Event of Right Mouse Button Down:

    Bullet.Pick By Position = Samus.Image Point.


    Bullet.Pick By Closest To(Samus.ImagePoint or Position)

    Also note, that the Always Event I put is NOT in the same SUB-Event as the Trigger Once Event. It's a seperate SUB-Event of the "Right Mouse Button Down" Event.

    So it would be something like this:

    + Right Mouse Button Down:

    ++ [Trigger Once]:

    --> Create Bullet at Samus(ImagePoint)

    --> Set Bullet.Speed = 0

    ++ [Bullet.Pick By (Position = Samus.ImagePoint OR Closest to Samus.Pos) ++ Always]:

    --> Set Bullet.Position to Samus.ImagePoint

    --> Set Bullet.Angle to Samus.Angle

    + [Right Mouse Button Released: + Bullet.Pick By (Position = Samus.ImagePoint OR Closest To Samus.Pos)]:

    --> Set Bullet.Speed = 500

  • I usually do something like this:

    + MouseKeyboard: On Right mouse button Clicked

    -> System: Set global variable 'test' to 1

    //add here whatever is needed as soon as

    //the player moves the right mousebutton down

    //Clicked instead of pressed will only be triggered once per click

    + System: Is global variable 'test' Equal to 1

    //add here whatever is needed while the right mouse button is down

    ++ MouseKeyboard: On Right mouse button released

    //add to this subevent whatever is needed as soon as

    //the mouse button is released

    --> System: Set global variable 'test' to 0

    EDIT: This is without the 'proper picking' issue.

  • Try giving the Bullet a PV like 'fired' or something. Then try...

    + Right mouse button is down

    ++ Trigger Once

    --> Spawn Bullet Samus (@ Cannon)

    --> Set Bullet Speed = 0

    --> Set Bullet.Value('fire') = 0

    ++ if Bullet.Value('fire') = 0

    --> Position Samus (@ Cannon)

    --> Bullet Set Angle to Samus.Angle

    + Right mouse button released

    ++ if Bullet.Value('fire') = 0

    --> Set Bullet Speed = 500

    --> Set Bullet.Value('fire') = 1

    That should do it, I think. Not too complicated either, and only requires 1 additional PV.

  • That method worked best for me, but it is still attracting all instances (From the Single shot "Left Mouse") to the cannon if the Right Mouse is pressed for charging. Is there anyway to block the "Set Position" from working on the "Left Mouse" click event if it is fired then a charge right after?

  • Try a "For Each Object" condition. It's a System Object condition.

    ++ For Each Object (Bullet)

    ++ if Bullet.Value('fire') = 0

    --> Position Samus (@ Cannon)

    --> Bullet Set Angle to Samus.Angle

    + Right mouse button released

    ++ For Each Object (Bullet)

    ++ if Bullet.Value('fire') = 0

    --> Set Bullet Speed = 500

    --> Set Bullet.Value('fire') = 1

  • Didn't work sadly, and I also gotta work on not letting the Left Mouse (single shot) be triggered when a Right Mouse (charge shot) is still active. It's letting me continue to shoot regularly when I have the Right mouse held down.

    EDIT: I got the Left Mouse button to stop being called by just adding a GV to it. Checks if 0, if not, can't fire. Right Mouse sets the GV to 1 until released.

    Now my only problem is getting the Normal shots to not attract to the weapon if I press the Right mouse button. I already have a charge working along with a set time it is able to charge.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Actually I already told You how to solve the problem, which has to do with the picking of the bullet instances, so the other bullets won't be affected, but only the one currently at Samus' imagepoint.

  • Sorry, I misunderstood your problem. But the concept I gave you will still work, you just gotta make sure the normal bullets have the same check.

    Really though, I recommend Shindoh's suggestion above. I just gave it a lookover and it's pretty tight. Should work fine.

  • Shindoh

    Sorry I glanced over yours and didn't even think to try it before, that was my bad.

    Would the Bullet pick replace the PV? I tried implementing it, I could be doing it wrong but I had another problem. The bullets don't attract to the gun now, but rather they all grow along with my Charged growth of the bullet. All of the ones on screen grow, that could easily be with my Growth event and where it's at.

    Here is what I have.

    +Left Mouse pressed

    ++GV 'shotDisable' = 0

    ->Samus spawn Bullet (@ImagePoint)

    +Right Mouse down

    ->Set GV 'shotDisable' to 1

    ++Trigger Once

    ->Samus spawn Bullet (@ImagePoint)

    ->Bullet Set speed to 0

    ->Bullet Set 'Charged' to 0

    ++Bullet Pick closest (@Samus.Angle, )

    ++Bullet Value 'Charged' = 0

    ->Bullet set position samus (@Imagepoint)

    ->Bullet angle

    ++Every 750 ML

    ++Bullet Height < 90

    ->Set height to Bullet.Height+20

    ->Set width to Bullet.Width+20

    +Right Mouse released

    +Bullet Pick closest (@Samus.Angle, )

    ->Set GV 'shotDisable' to 0

    ++Bullet Value 'Charged' = 0

    ->Bullet set speed to 500

    ->Bullet set 'Charged' to 1

    EDIT: I just added to Pick condition to my bullet resize event. It worked, but it also bugged out if I shot multiple times then held down the charge button. It attracted all the bullets, and they spazzed out around the gun. I know this is probably due to the same condition in 2 diff events.

    EDIT2: I tried the Pick Closest method without the PV and it is still doing what I mentioned above. It is dragging the closest instance of Bullet to Samus then releasing it when I release the button. It is also charging all instances of Bullet on the screen because of my Resizing event for the charging action.

    I also am not sure if I am doing it right, but I have the Pick Closest to conditions as this on both events:

    Bullet Pick Closest to Samus.ImagePointX("Cannon"), Samus.ImagePointY("Cannon")

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