Linear curve for RPG leveing...

I know this has been asked before, but I’m not understanding how it would be implemented into my system…

  1. I have Lvl, that’s the part in my database that one selects
  2. I need first ‘Starting Exp’ once Lvl is selected
  3. Then from Starting Exp I need ‘To Next’.

I want to do just a linear curve. The thread I’ve been examining is here:

Someone explains there:

…I don’t get that…I have level, the part I need is first experience THEN the experience to next variables…

Wouldn’t it be easier to just add a modifier that determine the current max-xp value? Something like:

private const float XP_MODIFIER = .33f;

private float _curXp;  //Currently attained xp
private float _xpToLvl;  //Target xp to gain before leveling up
private int _lvl; //current character level

public void GainXP( float f ) {
     _curXp += f;

     if( _curXp >= _xpToLvl ) {
          OnDing();
     }
}

public void OnDing() {
     _lvl++;
     float nextCap = _xpToLvl + ( _xpToLvl * XP_MODIFIER );  //Increase target XP value by 33% of it's previous value
     _xpToLvl = nextCap;
}

I’m gonna test out what you’ve posted.

I wasn’t really looking for a method that levels up the character, but rather I’m making a database manager in where you create a character and choose his/her starting lvl, so lvl is the thing that you select, and then it will start the character off at the beginning of that lvl.

So the programmer in me wants to do something like this (I’m terrible at math as you can tell):

int startingExperience = 0;
for (int x = 0; x < startingLvl; x++) {
   startingExperience += x * 100;
}

//result is our starting experience per lvl.

//then toNext:

int toNext = startingExperience + (startingLvl * 100);

I’m very simple minded and know nothing of logarithmic curves but this seems to create one in the simplest way I can think of.

I see things like this:

y = (x ^ 2)

…and have no clue how to implement it! It makes me feel like a noob.

Am I not understanding this correctly? I thought a linear levelling system meant each level requires the same amount of exp to increase.

1 Like

I feel like he’s making this far more complicated for himself than necessary and I’m not quite sure what he’s getting at with this code which would explain why he’s struggling.

Have you checked out this tutorial? I would start from scratch and use this.

The curve he is talking about is such that the amount needed to reach each consecutive level increases by a linear amount. For instance,

level    xp      to next
1        0       100
2        100     200
3        300     300
4        600     400

So you see, the total xp is a curve while the xp required to the next level increases linearly.

Based on the information you already gave, you should be able to get what you want using equation 2:

experience =(level^2+level)/2*100-(level*100)

Just run this formula twice, once for the given level and once for the given level + 1.

Alternatively, just take advantage of the fact that xp-to-next grows linearly:

to next = level * 100
1 Like