
Originally Posted by
scrapland
@Spoof
Ok your Code works. But now when i levelup it gives me Negativ XP.
So it hast to be a mistake in the CalculateFuntion.
Code:
private function CalculateLevelProgress()
{
Local int xpToCurrentLevel;
xpToCurrentLevel = 0.5*Level*(Level-1)*CalculateXPIncrement(Level);
XPGatheredForNextLevel = XP - xpToCurrentLevel;
XPRequiredForNextLevel = Level * CalculateXPIncrement(Level);
}
@DennyRoket Yes i know this might be a stupid question.
I will look some tutorials on UnrealScript. But this question was more detailed so i didnt know where to look for!
As Mons points out, at level 1 those calcs will evaluate to 0 due to "*(Level-1)". However, the algorithm makes sense when you consider that you don't need any xp to get to level 1 because you start at 1.
Your progress calc makes me dizzy
. I would simplify it down to:
Code:
var int Level;
var float XP;
// Calculate total xp for a specific level
function float GetXPForLevel( int inLevel )
{
return 60 * ((inLevel ** 2.8) - 1);
}
// Get the proportion of progress toward next level
// Returns unit scalar, 0.0 to 1.0
function float GetProgress()
{
local float current, next, required;
current = GetXPForLevel(Level);
next = GetXPForLevel(Level + 1);
required = next - current;
return (XP - current) / required;
}
DefaultProperties
{
Level = 1
}
And if you want the amount of xp remaining to level...
Code:
function float GetRemainingXP()
{
return GetXPForLevel(Level + 1) - XP;
}
And also, since we're working on the basis of a target level, the AddXP() function needs to change:
Code:
function AddXP( float inXP )
{
XP += inXP;
if( XP >= GetXPForLevel(Level + 1) )
{
LevelUp();
}
}
EDIT: GetRemainingXP() was wrong, fixed.
Bookmarks