Trying to figure out some math

Hello everyone,

I did once a game in gamesalad about 3 years ago and now I'm back in hope to complete another game. Had this idea and was able to setup good portion of the game mechanic but am running into math situation I have no idea how to tackle, and hope I can get help here please.

I have an actor I spawn every 3 seconds and it moves along X axis at 300 speed. As you can imagine what you'll see is the same actor repeat at specific distance from each other. Now I want to increase after 5 seconds the speed by lets say 10%. Logical thinking would say I need to decrease the spawning time by 10% if I want to maintain the distance between each actor the same, but it is not. How can this be solved please?

Thanks,

Doron

Best Answer

  • tatiangtatiang Posts: 11,949
    edited April 2015 Accepted Answer

    Here's the equation you need to use:

    Distance between actors = speed * spawn delay

    So if your actor initially spawns every 3 seconds and moves at a speed of 300 pixels per second, your equation would be 900 = 300 * 3. As you increase the speed by 10% to 330, you need to recalculate the spawn delay. So your new equation would be 900 = 330 * d. Solving for d would result in 2.73 seconds. Based on this, you would constrain the distance between actors to the speed times the spawn delay.

    Demo here. I can't promise it's perfect but I think it's a start! Note that I set the actor speed to 100 because at 300 it's hard to tell if it works (though it should). Press the 'x' key to log the actors' positions so you can see their "distance between."

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • SummationSummation Member, PRO Posts: 476

    @karuzo How about multiplying your speed by 1.1 if you want to increase it by 10 percent?

  • karuzokaruzo Member Posts: 35

    @Summation said:
    karuzo How about multiplying your speed by 1.1 if you want to increase it by 10 percent?

    Thanks for the quick reply. If I understand you correctly, I don't that solves my problem, as the distance between actor still increases and not maintained at same distance from each other.

  • SummationSummation Member, PRO Posts: 476

    @karuzo Which speed are you increasing? The spawn speed, or the movement of the actors?

  • karuzokaruzo Member Posts: 35

    @Summation said:
    karuzo Which speed are you increasing? The spawn speed, or the movement of the actors?

    Increase the actor's movement speed and decrease the time the actors are spawned. There is a need to maintain a ratio between the two variables so the distance between the appearing actors remain the same visually.

    Thanks.

  • karuzokaruzo Member Posts: 35

    @tatiang said:
    Here's the equation you need to use:

    Distance between actors = speed * spawn delay

    So if your actor initially spawns every 3 seconds and moves at a speed of 300 pixels per second, your equation would be 900 = 3003. As you increase the speed by 10% to 330, you need to recalculate the spawn delay. So your new equation would be 900 = 330d. Solving for d would result in 2.73 seconds. Based on this, you would constrain the distance between actors to the speed times the spawn delay.

    Demo here. I can't promise it's perfect but I think it's a start! Note that I set the actor speed to 100 because at 300 it's hard to tell if it works (though it should). Press the 'x' key to log the actors' positions so you can see their "distance between."

    Thank you tatiang - apology for responding only now as I have not had the time to look into this until now. Works great.

    Doron

Sign In or Register to comment.