2017-02-05 20:32:44

Hi guise. I have a bullet class which creates an object, then that object moves with a for loop and when ever it hits an object, so it does something.
But i see a problem in it. A bullet should be fast, very fast. But this one isn't. For example, when you fire your weapon, it takes about one or half a second to reech 50 or 60 steps after itself and this shouldn't happen. But actually i've seen a fiew games in bgt that uses a very nice bullet system like preless harts and psyco strike. They have a very awesome bullet system, with a very nice bullet speed. Could anyone please help me about this eshu?
I'm looking for it for an almost long time. I even have set the timer to 1 mili second but it was still very slow.
thanks

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2017-02-05 21:41:06

It's hard to tell without seeing how your game is set up all together.
What I normally do is set up a master clock for the game, usually around 50fps (20ms per frame). Then to save myself the headache, immediately convert that into seconds at the start of my main step function, then pass the amount of time that passes to all the objects which need updating.
If you can move a maximum of one step per frame, that's still 50 steps per second. The answer is to move more than one step per frame, if you need to go faster.
Normally, I'd just make the bullet bigger than it would actually be, to represent the path it travels through in a single frame, but you can just say that if you're moving more than you can test in a single step, to do smaller steps in the same frame.
But if you turned the timer down to 1ms/frame, then the problem is probably not the bullet class, but the overall framerate. You can fix thisin the bullet class by moving more than one step per frame.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-02-06 17:36:27

Here's my class. And if i do what you said(If i get you correctly), bullets might miss the target or go over the walls.
https://www.dropbox.com/s/ovi7iva2z6dx4 … t.bgt?dl=0

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2017-02-06 18:26:14

The link is throwing a 429 too much traffic error.
When I said more than one step per frame, I meant something like a loop or recursion. Obviously, you don't want to skip spaces, otherwise you get the bullets-going-through-walls problem that is an issue if not specifically planned for.

Like, here's a bit from the character class in my current project, in the part that handles movement:

    void always(double dt) {
        shape@ targ=this.bounds.translate(this.v.x*dt, this.v.y*dt);
        
        // (Bunches of other things...)
        
        if(!targ.intersects(this.bounds)) {
            this.v*=0.9;
            this.always(dt*0.5);
            return;
        }// moving too fast.
        
        // (etc)
        
    }// always.

But I also make sure my small objects have bounds that let them move at the speed I want. You can modify that bit to make it stay at the same speed, but it's important to be careful when using recursion like this.

So, your bullet class could have the move function use a loop, and when I say it moves more than one step per frame, it does the full movement check and everything for each step--it just does this 2 or 3 or 8 times per frame.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-02-06 18:55:02

That's some very advanced code. These people seem like beginners so I wouldn't get that advanced. Just my opinion though.

CAE_Jones wrote:

The link is throwing a 429 too much traffic error.
When I said more than one step per frame, I meant something like a loop or recursion. Obviously, you don't want to skip spaces, otherwise you get the bullets-going-through-walls problem that is an issue if not specifically planned for.

Like, here's a bit from the character class in my current project, in the part that handles movement:

    void always(double dt) {
        shape@ targ=this.bounds.translate(this.v.x*dt, this.v.y*dt);
        
        // (Bunches of other things...)
        
        if(!targ.intersects(this.bounds)) {
            this.v*=0.9;
            this.always(dt*0.5);
            return;
        }// moving too fast.
        
        // (etc)
        
    }// always.

But I also make sure my small objects have bounds that let them move at the speed I want. You can modify that bit to make it stay at the same speed, but it's important to be careful when using recursion like this.

So, your bullet class could have the move function use a loop, and when I say it moves more than one step per frame, it does the full movement check and everything for each step--it just does this 2 or 3 or 8 times per frame.

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2017-02-07 14:50:54

CAE_jones, Thank you! I got your meaning and it's a very nice idea. We will do this soon.
Thanks again.

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988