Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Linear curve for RPG leveing...

Discussion in 'Scripting' started by astracat111, Apr 27, 2018.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    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:
    https://gamedev.stackexchange.com/q...alculating-a-level-based-on-experience-points

    Someone explains there:

    ...I don't get that...I have level, the part I need is first experience THEN the experience to next variables...
     
  2. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    Wouldn't it be easier to just add a modifier that determine the current max-xp value? Something like:

    Code (CSharp):
    1. private const float XP_MODIFIER = .33f;
    2.  
    3. private float _curXp;  //Currently attained xp
    4. private float _xpToLvl;  //Target xp to gain before leveling up
    5. private int _lvl; //current character level
    6.  
    7. public void GainXP( float f ) {
    8.      _curXp += f;
    9.  
    10.      if( _curXp >= _xpToLvl ) {
    11.           OnDing();
    12.      }
    13. }
    14.  
    15. public void OnDing() {
    16.      _lvl++;
    17.      float nextCap = _xpToLvl + ( _xpToLvl * XP_MODIFIER );  //Increase target XP value by 33% of it's previous value
    18.      _xpToLvl = nextCap;
    19. }
     
  3. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    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.
     
  4. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    So the programmer in me wants to do something like this (I'm terrible at math as you can tell):

    Code (CSharp):
    1. int startingExperience = 0;
    2. for (int x = 0; x < startingLvl; x++) {
    3.    startingExperience += x * 100;
    4. }
    5.  
    6. //result is our starting experience per lvl.
    7.  
    8. //then toNext:
    9.  
    10. int toNext = startingExperience + (startingLvl * 100);
    11.  
    12.  
    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.
     
    Last edited: Apr 28, 2018
  5. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Am I not understanding this correctly? I thought a linear levelling system meant each level requires the same amount of exp to increase.
     
    Lethn likes this.
  6. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    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.

     
  7. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    The curve he is talking about is such that the amount needed to reach each consecutive level increases by a linear amount. For instance,

    Code (data):
    1. level    xp      to next
    2. 1        0       100
    3. 2        100     200
    4. 3        300     300
    5. 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:
    Code (maths):
    1. 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:
    Code (maths):
    1. to next = level * 100
     
    astracat111 likes this.