Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Theory with level up and xp

Discussion in 'Scripting' started by Resilo, Dec 6, 2017.

  1. Resilo


    Dec 8, 2016
    So just need some advice on the skill leveling system i need

    so for example lets say i have the skill unarmed

    and unarmed levels up at 3 xp

    but it triples every level so level 2 will take be at 9 xp

    so i think the easiest way is either with an array or a list

    theoretically the list would just say that its 100 long(as the skills max is 100) and that every entry is 3* the last entry

    what would be the best way to go about this? and what would a brief example look like?
  2. MaxGuernseyIII


    Aug 23, 2015
    How accurate does it need to be? Math.Pow can get you darn close and will be very precise but it will lose accuracy as the number of xp required goes up because it uses floating point arithmetic.

    If you need absolute accuracy in that formula, you'll want to use integers and loop through multiplication. Although, as I'm typing this, I'm realizing you can't have an integer that stores 3^100, so maybe you're stuck with floats/doubles anyway.

    I'd try to find a way to be happy with doubles and Math.Pow...
  3. LaneFox


    Jun 29, 2011
    Code (csharp):
    1.         public static int GetXpRequiredAtNextLevel(int currentXp)
    2.         {
    3.             return currentXp * 3;
    4.         }
    Resilo and Ryiah like this.