How do I properly set bullet direction (for a portal gun!)

Get help using Construct 2

Post » Sat Aug 02, 2014 12:30 am

Hey all, I've been working on a simple idea for about 2 days. What if I could create a game that has a character with mechanics similar to portal? I.E. he has a portal gun and can open up portals at will. I've been working on it a lot. I found a post about making portals that really helped and with some modifications I managed to make 2 way portals and I can open new portals with my gun But I do have problems...

[list=]
[*]I can't change the bullet direction, only the angle that the subsequent portal opens at
[*]I can't reduce rate of fire, not sure what I'm doing wrong
[*]Is there anything else you can see that is blatantly bad? I'm trying to make it in a way that leaves things open to have many, many playable characters.
[/list]

I'm new to Construct 2 (that's probably obvious) but I am an experienced software engineer, so I may be approaching these issues from the wrong frame of mind. Any advice you have would be extremely appreciated.

EDIT:
Also, it seems I suck at using this forums tags!
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 15
Reputation: 235

Post » Sat Aug 02, 2014 5:32 am

The quickest way I found to fix your bullet direction was to put a sub-event under the z key event, that says:
if portalmanimage is mirrored, set bullet angle of motion to 180.

and to fix the rate of fire to a single shot per button press., change "z is down" to "z is pressed"

the X key isn't doing anything, There's so much going on there, I'm not going to try and decipher it.
But I'm guessing you don't need all of those sub events under there. I might be wrong, though... Just not really sure what's going on there.

Anyways, hope that helps ya some..
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Sat Aug 02, 2014 5:51 am

here is a fix for your angle problem:

fix.capx
You do not have the required permissions to view the files attached to this post.
Image
B
71
S
28
G
12
Posts: 515
Reputation: 12,284

Post » Sat Aug 02, 2014 7:47 am

Spacedoubt, 'z 'was there as a placeholder, 'x' is the one I was actually working on. I know it looks complicated, but I'd like to walk you through the process a bit, my plan was to:

when x is pressed and a bullet's boolean value of ready is set to true

spawn a bullet
set the angle of that bullet to a value corresponding to the pressed arrow keys (8 directions)
Then set "Ready" to false signifying that the gun has been fired and can't be re-fired yet
wait for a "reload time" that is set within the portal bullet
and finally set ready to true signifying a new bullet can be pressed.

Because I was intending for 8 directional shooting, not 2 directional shooting, I need something a bit more complex than simply looking at the direction the shooter is facing. (Further, the most glaring problem was that I was setting the bullet's angle rather than the angle of motion.)


Lof, the fix works great! I can see you took the time to not only fix it but also use better programming practices. I really appreciate the effort you clearly put in. I would love it if we could talk about it a bit though.

I see that you gave the shooter a "fireAngle" attribute that holds the direction that he's currently firing, Then you simplify it by having the shooting and the setting of the angle as two different steps, that way we can reduce a lot of repeated code, I really like the more modular approach.

The only problem is, I was hoping to use the reload time to limit the rate at which the player can fire (I only set it to 3 seconds to exaggerate it for testing, in the real game it will be a much shorter time). The player can get around this pre-imposed limit simply by mashing the 'x' button. How could I change it so that the player is unable to shoot for a specified amount of time after each shot? Similarly, is there a way I can limit the number of bullets that can exist onscreen at a given time... i.e. The bullets are destroyed offscreen (I know that can be set in behaviors) and while there are 3 or more on screen, the player can't shoot.
B
5
Posts: 15
Reputation: 235

Post » Sat Aug 02, 2014 7:56 am

you can simply check it with the count expression
condition
system
compare 2 values
if
bullet.count < X
fire
Image
B
71
S
28
G
12
Posts: 515
Reputation: 12,284

Post » Sat Aug 02, 2014 8:33 am

that's good for limiting the number of bullets on the screen at 1 time, thanks

how can I limit the rate of fire?
B
5
Posts: 15
Reputation: 235

Post » Sat Aug 02, 2014 8:47 am

If I'm understanding you right, you could create a counter variable that decreases every tick and resets when the fire button is pressed. Then make an if statement that limits the firing to only be if counter < 1.
If you're saying what I think you're saying, theoretically this should work. The higher you reset the counter value to, the longer it will take for your ammo to recharge.
B
9
S
3
Posts: 22
Reputation: 755

Post » Sat Aug 02, 2014 8:54 am

here you go:
fix2.capx
You do not have the required permissions to view the files attached to this post.
Image
B
71
S
28
G
12
Posts: 515
Reputation: 12,284

Post » Sat Aug 02, 2014 8:56 am

@JayZX535 it would be much harder setting the correct value using every tick, i just added another var isFiring 0 and 1
and i wait the amount of fireRate in between.

a tick is not absolute, it varies depending on many variables, you can miss a lot of ticks in slower machines.
well theoretically even a second is not absolute, but it's closer.

but then again you can use dt.
Last edited by Lof on Sat Aug 02, 2014 9:08 am, edited 2 times in total.
Image
B
71
S
28
G
12
Posts: 515
Reputation: 12,284

Post » Sat Aug 02, 2014 9:06 am

Lof wrote:@JayZX535 it would be much harder setting the correct value using every tick, i just added another var isFiring 0 and 1
and i wait the amount of fireRate in between.

That could work too, though I've had some glitches trying to do something like that with moving through dialogue. It could have just been something I missed, though :P
B
9
S
3
Posts: 22
Reputation: 755

Next

Return to How do I....?

Who is online

Users browsing this forum: blissfulwizard, DevinMurray, Yahoo [Bot] and 15 guests