Bullet spread doesn't seem to wanna work.

0 favourites
  • 14 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • Okay, so I have checked a metric crud ton of forms out there and they all have similar "solutions" to my problem, note I had that in quotes.

    They seem to work for other people, but I have a particular case that prevents what other people have work for them work here.

    Like for example people say to randomize the face in which the player is facing by small margins then fire a projectile which has its motion unchanged its just the angle the player was facing that changes the direction its fired giving the illusion of spread, but I am not doing that because the gun is SEPARATE from the player.

    So, I'm forced to do the real deal.

    I am spawning in a bullet, upon creation that bullet has its angle of motion changed according to a random number

    ( I used all the randomizers out there, with similar results; )

    so either itd be floor(random(x,x)), round(random(x,x)), int(random(x,x)) Whatever:

    If there is a error in any of these examples, don't mention it as it's not the point.

    They all work to make the trajectory random: But thats the problem.

    I want the direction the gun is facing PLUS a randomizer.

    So you fire it forwards? Okay, add a 10 degree randomizer IN THAT DIRECTION.

    That is the desired effect: Now clearly, I can't do this with a randomizer alone: I need to add it over the direction the gun is facing.

    But as of now I have no clue how to format that: Anyone have an idea on how that would be written?

  • Currently I've tried

    " Gun.Angle + int(random(10, -10)) "

    &

    " int(Gun.Angle + random(10, -10)) "

    Both do the same thing just written differently with the result shown in the gif below.

    Hoping this gif works...

    https://i.gyazo.com/e23b28a0e88ed3b9ab107558699a10d2.gif

  • Hello.

    Not sure what you don't like?

    On the gif you can see that the bullets fly with a spread.

  • Gun.Angle + int(random(10, -10))

    You don't need int() - it will make the spread slightly asymmetrical.

    Otherwise I agree with igortyhon, there is nothing wrong with your gif.

  • There is one thing wrong, I want inaccuracy, Spread, bloom whatever you'd like to call it.

    I don't want a shotgun I want a single bullet to be fired from the gun with inaccuracies to it.

    I know my phrasing is off; Pardon me.

  • Ok so I found something quirky with this, apparently more than one bullet is spawned even though, the event itself only spawns in ONE bullet.

    I'm going to tinker with this, if this just so happens to be the problem, I'm going to laugh.

    Trying to add a Trigger once while true event while this happens, see if that fixes it.

    Then I'm going to share how I fixed it to everyone here so that if another person has this problem; I can show them how to fix it.

  • Okay so it did work, I had to make some adjustments to how it's done, instead of using bullet angle I just used the default angle thingy.

    For the shotgun nonsense I just put a trigger once, so that's wrapped up and doesn't do it anymore.

    So, for those of you whom are curious it seems bullet angle works best with a randomizer constantly changing its current value, say it stored somewhere as a number variable.

    I didn't do that here, because that'd be bulkier, I think.

    I simply used angle and what I wrote was this:

    " Gun.Angle + int(random(10, -10)) "

    Gun.angle is where the gun is facing, make sure it has a second image point thats set to the end of the barrel.

    Then you put a plus and ADD the randomizer of your choice.

    All I have to say is I love it when I end up fixing my own problems.

    Always use debug ladies and gentlemen, always; Otherwise you'll spend a year like I did trying to figure this out on my own before giving into using forms.

    ( Which isn't bad, always ask for help even if its literally copy and pasting code. )

  • Now for anyone curious as to how it looks: Here you go.

    https://i.gyazo.com/88d53f0324aaf87b852915118259339c.gif

  • Now I can add recoil separately from the accuracy of the gun, just to be more realistic.

    I may make a " How do I " page that answers this question and shows how to make everything in my game.

  • Why additional events, waits, trigger once etc.? Just spawn the bullet in the same event you set the "fire" animation and adjust its angle of motion. And give it "Destroy outside layout" behavior, so it would be destroyed automatically.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A simple implementation of a machine gun with a spread of bullets.

  • Why additional events, waits, trigger once etc.? Just spawn the bullet in the same event you set the "fire" animation and adjust its angle of motion. And give it "Destroy outside layout" behavior, so it would be destroyed automatically.

    The reason being I can interact with each individual part; general rule of thumb is to inflate a project before compacting it.

    That plus I like individuality and I may come up with a unique way to tackle a problem in the process.

    Can't always do that if I'm doing what everyone else does.

    But yeah, your definitely right; I will compact it in the future when the game releases as it'll be critical when I want to add more firearms.

  • It's just a very common thing beginners do in Construct - they add a new event for everything. Then they discover these events affect all instances and not just the one they want, or that events are firing on every tick instead of just once. People try to fix this by creating complex "state machines" and by adding "trigger once" conditions in every event. And often end up with an entangled and still buggy code.

    When you spawn a new instance, it's better to perform all initial actions with it in the same event. And avoid using "trigger once" condition, especially with multiple object instances.

  • Interesting, it's a good thing I have reason for it, and it isn't just because I don't know how to compact it.

    Even if I didn't there is plenty of room for finding out.

    But either way I consider this topic closed as I ended up figuring out what the problem(s) were on my own whilst showing how it was done.

    As stated in my finished post I may show how you'd go about doing this and by then adjustments would be made.

    Some are quick to assume that it was a beginner issue, and I was kinda hoping to avoid that by asking to get straight to the point which didn't happen until I explained the problem further, which led me to the answer, which was literally a button click away, wheeze.

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