How do I keep my bullets from changing direction?

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Hi,

    I have a Boss who spawns a bullet object (Eball) every three seconds, whenever he gets Line of Sight to the Player. That part works.

    But the Boss is set to travel back and forth in the Boss chamber, changing direction whenever he hits the wall.

    And the bullets do the same thing. If they're still onscreen, they will change with him. Otherwise they get Destroyed when they go offscreen.

    How to make the bullet's independent so that they don't follow the Boss's direction? Code below (for Boss movement and bullet spawning):

    Is it a setting in the Bullet Behaviour for the bullet object (Eball)?

    Any suggestions etc. greatly appreciated,

    thanks,

    M

  • Well maybe that's not what's happening now.

    NOW, since I'm destroying the bullet every time the Boss changes direction, the bullet does NOT change direction as previously stated. But the bullet disappears when the Boss changes direction, which looks odd.

    I'm having the bullet destroyed because when I don't, the bullets DO change direction with the Boss.

    At this point, trying to figure out how to keep that bullet on screen (not being destroyed mid-flight) when the Boss abruptly changes direction.

    I added the Fade behaviour to the bullets so that they taper off in opacity and we don't notice any abrupt exiting.

  • I don't see the issue with the events you posted, but you said that those aren't the events that were causing the problem, so that doesn't help much.

    Anyway, I've had similar issue, the problem was if you spawn a bullet then change the direction you are fine, but if the bullet gets destroyed before the the angle is set then it picks all the bullets. LOS may be going in and out quickly? not sure, so maybe this doesn't apply.

    Anyway, first thing I would try is 'On Bullet Created' -> set angle to: boss.direction = "right" ? 0 : 180

    (if you don't know the ?: I recommend learning, very useful)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks badmoodtaylor, that bit of code worked, however I confess I don't understand the ?.

    I ended up setting the angle of the bullet to 180 or 0 based on whether the Boss is mirrored or not. That's because I also changed the Boss so that he always faces the Player, whether he's moving away or towards him. It's looking good, in a simple as shit 8-bit boss kind of way, thanks for your help!

  • You are welcome. the ?: looks confusing at first glance but it is very simple. Type a condition then put a question mark. Then type the result if true, put a colon : and then what the result is if false.

    So to test it out if you have a global variable called SCORE and a textbox, choose the action set text and type:

    Score < 200 ? "Good" : "Great"

    If score is less than 200 the textbox will say good. 200 or more and the texboxt will say great.

    Description from elsewhere:

    [quote:3klt24eh]

    ?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false

    e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".

    The condition counts as true if it is non-zero, and false if it is zero.

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