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

0 favourites
  • 13 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • 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...

    • 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.

    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.


    Also, it seems I suck at using this forums tags!

  • 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..

  • here is a fix for your angle problem:


  • 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.

  • you can simply check it with the count expression



    compare 2 values


    bullet.count < X


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

    how can I limit the rate of fire?

  • 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.

  • here you go:


  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • if I may ask, why use an int rather than a boolean for isfiring? Booleans seem like a more natural fit for something like this.


    Oh boy, I hope I'm not turning into a help vampire. I see I can destroy my bullets easily once they're outside the layout, what if I want them to be destroyed the moment they're offscreen?

    EDIT 2:

    Found it! But is the everytick, isonscreen efficient? I am inclined to minimize the everytick stuff.

  • isonscreen is being checked everytick as it is, no need to add another condition.

    about the isFiring, you can use a boolean, it will work the same.

    i usually like to use vars, the later if i want to add another state of the condition i can use other numbers.

    for example you can set it to -1 to disable firing, or to 2 for another state of firing etc.

  • That makes a lot of sense. I think that wraps up this thread nicely, thanks again for all the help

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