Limiting Spawn on Continuous KeyDown

For questions about using Classic.

Post » Mon Feb 27, 2012 9:20 am

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.

Charge_Test

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!RTCook2012-02-27 09:22:05
B
2
Posts: 5
Reputation: 260

Post » Mon Feb 27, 2012 12:41 pm

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)
>>Always:
->Bullet: Set Position to another Object('Samus', 'CannonPoint')
->Bullet: Set Angle = Samus.Angle

B
3
G
1
Posts: 70
Reputation: 615

Post » Mon Feb 27, 2012 4:46 pm

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.RTCook2012-02-27 16:51:25
B
2
Posts: 5
Reputation: 260

Post » Tue Feb 28, 2012 4:23 am

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.

OR

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
B
3
G
1
Posts: 70
Reputation: 615

Post » Tue Feb 28, 2012 4:37 am

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.tulamide2012-02-28 04:39:51
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Feb 28, 2012 1:40 pm

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.
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Tue Feb 28, 2012 11:52 pm

@TL22

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?
B
2
Posts: 5
Reputation: 260

Post » Wed Feb 29, 2012 6:54 am

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
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Fri Mar 02, 2012 11:53 pm

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.RTCook2012-03-03 01:54:30
B
2
Posts: 5
Reputation: 260

Post » Sat Mar 03, 2012 4:00 am

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.
B
3
G
1
Posts: 70
Reputation: 615

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests