1
$\begingroup$

I am trying to create a game in wich there are 2 threads running constantly, one for the car controls and another one for determining the speed. The speed is calculated by comparing the car's current position to the position 0.1 seconds after (for wich I use time.sleep(0.1))

The thing is, I want the thread that determines the speed to start again only when is has finished, for this I use threadSpeed.isAlive(). But i think that when i use time.sleep, the thread shows up as not alive and so it starts generating many times, messing the program and throwing errors, so the question is: Is there a way to generate a delay without time.sleep? or is the problem totally unrelated? Thanks.

$\endgroup$
0
$\begingroup$

Why do you want to calculate the velocity by yourself? It's already provided by the API with getLinearVelocity

Alternatively - in case you really want to do it yourself - you could use the "Skip" Setting in the Always Actuator to tell Blender it shall execute your own velocity calculation only every n-th game loop.

Hope this helps!

$\endgroup$
0
$\begingroup$

It makes not much sense to use asynchronous processing within a synchronous environment unless you expect it exceeds the available time.

I suggest you stay with the proven concept:

Time period = 1 logical frame Calculate controls once per logical frame Calculate speed once per logical frame.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.