1
\$\begingroup\$

I want a stream of enemies coming from the top of the screen one behind other in a line, with their speed (speed of the whole stream i.e. every enemy) increased over time.

When I simply increased their speed, a continuous stream of balls (which will be my enemies) is lost since objects are spawned at a fixed time interval irrespective of the varying speeds of the spawned balls.

To maintain the continuous flow of balls what I wanted is to generate balls rapidly as the speed increases. So there should be a direct relationship between spawning interval and speed of the stream.

How can I do that?

\$\endgroup\$
5
\$\begingroup\$

This is a simple application of the distance-velocity-time triangle:

Diagram showing relationships between distance, speed, and time.

(Image via BBC "Bitesize Maths")

float timeBetweenSpawns = spaceBetweenBalls/ballSpeed;

This relies on your units being consistent between the three variables. So if timeBetweenSpawns is measured in seconds then the spaceBetweenBalls should be measured in world units and the ballSpeed measured in world units per second.

\$\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.