Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darkal · Jun 12, 2014 at 01:55 AM · javascriptmathlevelxp

xp math equation help

i want to make the same formula runescape has for leveling up in my code but i am unsure of how to put the equation in javascript here is my current code alt text

 #pragma strict
 var gain : boolean = false;
 var i = 10;
 var xp = 0;
 var lvl = 1;
 var x = 0;
 var lvlup : boolean = false;
 var item : GameObject;
 var spawn : Transform;
 
 var w = 0;
 
 function Start () {
 
 }
 
 function Update () 
 {
     //runescape math equation here
     x = w;
     
     
     if(gain)
     {
         xp += i;
         gain = false;
     }
     
     if(xp >= x)
     {
         lvlup = true;
     }
     if(lvlup)
     {
         lvl += 1;
         xp = xp - x;
         lvlup = false;
     }
 }
 function OnGUI()
 {
     if(GUI.Button(Rect(0, 0, 100, 100), "xp"))
     {
         Instantiate(item, spawn.position, spawn.rotation);
     }
     GUI.Box(Rect(0, 0, 100, 50), xp.ToString());
 }
 function OnTriggerEnter(other : Collider)
 {
     if(other.tag == "xpgain")
     {
         gain = true;
     }
 }


rs formula.jpg (9.8 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Jun 12, 2014 at 06:29 AM 0
Share

Do you really need that complex of an equation??!! This is extra computation for little bonus. If you were in a paid project and I would be paying you, I would tell you to keep that once all the core of the game is ready. But reality is I am not paying you so you can use it...

avatar image darkal · Jun 12, 2014 at 09:15 PM 0
Share

i like the equation it uses its good for my game granted i will change it by a small value but im trying to figure out how to plug that into my script in few lines as possible

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by zharik86 · Jun 12, 2014 at 06:25 AM

If you need to write a formula in your script, here(I wtrite on Java):

  function getNextExp(int curLvl): float {
   var nextExp: float = 1; // I initializate this value, because in case curLvl = 1, your formula don't work
   var tempic: float = 0;
   for(var i: int = 1; i <= curLvl -1; i++) {
    tempic = tempic + Mathf.Floor(i + 300*Mathf.Pow(2, i/7));
   }
   tempic = Mathf.Floor(tempic / 4);
   if (tempic > 0) {
    nextExp = tempic;
   }
   return nextExp;
  }

I hope it to you will help. But it is possible, for computation of XP it is better to use parabolic or logarithmic functions.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamic Level Progress Bar 1 Answer

Unity Exponentiation question. 1 Answer

Move speed not working properly 1 Answer

I want to translate an object when score changes but it doesn't work 2 Answers

How do I compare two binary values in Javascript? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges