# troubles with game logic. (controling a object spawning rate)

Well i have some trouble with game logic.
Maybe someone here knows how to solve it.
I asked here before for some help, and, well i decided to use this physics based version.
As in the end its physics what i want, (to be able to use sliding ramps, and box collisions with physics).

My problem is controlling the things that happen, the smaller black spiral works reasonable… (well it has the same problems). The problem sows more clearly in the big spiral (yellow black one), at first i had it all bind to one key “A” and later added “Q”, to better get control, over it, butputting it back to 1 key again would be fine.
(currently when keep pressing A as that would also trigger the big-spiral parts to spiral faster).

The problem is when they move faster they should spawn faster at starting point.
And when there is no speedup then they should spawn slowly
(so that i wont spawn to many of them, slowing down computer).

It turns out that for me its realy hard to control spawning speed and set it correctly
And i dont know what kind of logic rules i should follow, and how to improve it so that idealy with every speed they get spawned so they just touch each other. i tried a lot of combinations of setups the attached file is the best so far but still not ideal. Also i’m not realy sure if i have them setup correctly for this those nodes.BELTS3.blend (511 KB)

(so this is about the 2nd spiral after the sliding ramp).

Why not just measure that there is enough space to add a new one?

well i tried scaling them, the problem is the spawning interval, with two (or more) rotation speeds.
Even if there is a small gap wouldnt be a problem as long as the pink cubes dont slip trough
And a little overlapping isnt bad either.

I just cant get the spawning so that it for example on one speed does it do every X-th frame and on another speed every N-th frame.
Somehow keypressing is a actual current moment (i think its going wrong there) even with help of a variable, couldnt get it right.
So any delays on a current action, get delayed fo as long as the event is still trigered (key down) (…i think ??)

I’m not sure in what direction i should go to make this work.
Should i alter options in current nodes (level /tap )
Should i use delays instead of interval always, (been trying that for most of the time).
Should i use different method of key handling.
Alter timings
Maybe python to solve it somehow (not sure of direction),…
Should the plates be smarter(dye on another plate colission)
Should i use sensors (wait till there is enough distance to spawn a new one).
…??..

Note that i want to stick to this physics model, all my other plans i have with this work with it.

The problem is when they move faster they should spawn faster at starting point.
And when there is no speedup then they should spawn slowly
(so that i wont spawn to many of them, slowing down computer).

Out of this i would recommend to use properties, then if: prop1 == some value spawn object(s).
Everytime you spawn an object you set the value back to 0, so it counts again. this way you get a spawn rate you can control.

what about using a ray sensor or a few?

``````rays = [cont.sensors['Ray1'],cont.sensors['Ray2'],etc]

go=1
for sensors in rays:
if sensors.positive:
go=0
if go==1:
``````

a real conveyor belt uses laser sensors now any way right?

if the ‘adding new box’ area is clear, add a new box?

i tried to make it work with logic bricks and rays but couldnt do it, im trying to find some mre info about coding in BGE
i can code c# c++ but i need some kind of manual to know what everything does and how to access stuf, like internal / global variables or variables from other objects… probaply coding is the only way to solve this.
i see there is a BGE wiki, but not much code examples there to learn from, so this will put me to many hours of youtube to get a grip on it. Maybe i go look around at stack exchange or so… i’m not gonna give up on this

I’ll teach you bge python

just post what you have so far, or pm me etc, the best way to do it, is to keep learning by doing and try and have fun with it,

once you understand how to fix console errors it all gets easier each time, and you run into the same math all over the place,

against all the ods,… i got it working last night (at 4:00 in the night :)) ).
2 always triggers with an interval, and 2 keyboard controllers, one is configured on pressing A the other on not pressing A.
Basicly And and OR now determine wich always trigger is used. (always is based on frame count)
And now pressing A doesnt cause reset of waiting counters, and neither the key cause the start of the events, or does it cause problems with keyboard buffers

as there is som chance on a gap, by switching keypress state, i let them 50% overlap, resulting in no gaps anymore.

Another trick i applied in the belts, to have a counter add their rotational degrees, so its now easy to end object after 360 degrees a full turn or 720, for 2 turns