0 votes

Im making an endless runner game and I want the player's speed to increase every time his score increases by 10. How can I do this?

Godot version 3.4.1 stable
in Engine by (69 points)

1 Answer

0 votes
Best answer
  1. Introduce some difficulty scaling variable in scope high enough
  2. Raise this variable every 10 points of score using the same method that shows score in UI
  3. Apply this variable to whatever aspect of the game You need, like mobs speed = speed * this variable, or for x in range(this variable) spawn mobs every minute and so on
by (5,651 points)
selected by

Thanks, but how can I check whenever the score is increased by 10? I was thinking something like this:

*everytime score is increased by 10:*
     playerSpeed += 1

How would I change this into actual code?

You were making endless runner, so surely You were following tutorial from documentation. There is a method that counts the score, isn't there ? I thought there was setget function described ? I mean a place in your code when new points are added to old points ? In this same place You can check current score and apply calculations to it, for example :

on mob_killed():
     score += 10
     difficulty =ceil(score/10)

This calculation will result in ceiled integer of division score by 10, in other words, it will be 1 higher every 10 score. You can also make some maxscore variable, check if score is higher than maxscore, and if it is - raise the difficulty level by one and raise maxscore by chosen amount.
And in your movement code, calculate speed with difficulty however You like:

speed += difficulty
speed *= (1 + difficulty)/100
speed = speed.pow(difficulty)

Ok so I got it working now. I wasn't initially using setget but after you mentioned it I looked it up and decided to use it. Thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.