XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

2D shooter problem - Getting bullets and shots to look and function properly

Last post 24.07.2009 04:16 by woca. 5 replies.
  • 24.07.2009 02:24
    • (0)
    • premium membership
    • Posts 25

    2D shooter problem - Getting bullets and shots to look and function properly

    I currently have a very basic shooter. The problem is that the bullet's  just skip pixels, like programmed. I have a picture. the thing is the picture could be a video. If I hold the trigger down that is what I see. The pattern never breaks, unless I move reticle, then it starts again. Right now my 'bullets' simply change their position, so they skip some spots, and then the collision detection is messed up to.

    The code is below. I guess the code isn't really important, I know how it's working. What I want to know is how do I make them look good as if they go through each pixel or however you want to put it(animations?) and if there is a good sample.

            public void fireProjectile(Vector2 loc) 
            { 
                foreach (projectile ball in bullets) 
                { 
                    if (!ball.alive) 
                    { 
                        ball.alive = true
                        ball.position = loc; 
                        ball.velocity = new Vector2( 
                            (float)Math.Cos(firstPlayer.angle), 
                            (float)Math.Sin(firstPlayer.angle)) * 15f; 
                        return
                    } 
                } 
            } 

  • 24.07.2009 02:46 In reply to

    Re: 2D shooter problem - Getting bullets and shots to look and function properly

    Answer
    Reply Quote
    The problem you're noticing is a common one, one that Shawn Hargreaves explains in great detail here:

    Whenever the frequency at which you are sampling some data reaches half the repeat rate of that data, you have a problem. This is a magical value called the Nyquist frequency, and when you hit it, things start to go wrong. In the case of moving too quickly over a repeating ground texture, the symptom of the problem is an optical illusion where the texture will appear to stop moving, then gradually start to slide in the opposite direction. This is the same thing that makes wagon wheels spin the wrong way in old cowboy movies, and can be immensely distracting!

    Well, it's related anyways :-) your problem is that you're firing entirely too many bullets at once.  If you limit the rate at which your shots fire, they will look more natural :-)
    Joel Martinez - XNA MVP
    Blog: http://codecube.net
    XNA Unit Testing: Scurvy Test
  • 24.07.2009 03:01 In reply to

    Re: 2D shooter problem - Getting bullets and shots to look and function properly

    Wow that is a lot of bullet's.
    Depending on what your trying todo you could make a class which contains certain things like maxAmmo, rateOfFire, clipSize etc. And depending on your current selected gun use there attributes.
    You could even go a step further and add a type of mini-delay between each shot. But overall you should limit the bullets. (to what Joel Martinez said, about the natural look, well really it does just depend on what type of game he/she is trying to make. Say for instance a space side scroller, is a good example of crazy bullet usage :p)
  • 24.07.2009 03:10 In reply to
    • (0)
    • premium membership
    • Posts 25

    Re: 2D shooter problem - Getting bullets and shots to look and function properly

    should I not worry about this then? The game will have a sort of ammo/energy counter so you can't shoot a a lot. if the person stood still and held the trigger for 10 shots, it still looks like that at first, I guess then it;s really not a problem though

    I did shoot a few shots and kept moving. it looked fine then
  • 24.07.2009 03:26 In reply to

    Re: 2D shooter problem - Getting bullets and shots to look and function properly

    No, you should limit a gun to some extent or like most games do have a delay between shots.
    Stay for instance on some games you start off with a pistol, but you have unlimited ammo, there is always a limit in clip sizes, (so you had to reload) Or was a delay between shots.
    You should defiantly have 1 of them if not both. There's no way there should just be a continuous stream of bullets. Like in your picture.
  • 24.07.2009 04:16 In reply to
    • (0)
    • premium membership
    • Posts 25

    Re: 2D shooter problem - Getting bullets and shots to look and function properly

    hahaha, i kinda was getting far to caught up in the line. I'm not sure which of these is the answer. I guess the problem was found and it's no problem because there will be some limit and each shot isn't going to be totally accurate


    PS - not to be rude, but to those suggesting various things, if you don't know the game you can't really suggest what I should do in terms of gameplay
Page 1 of 1 (6 items) Previous Next