Forum begins after the advertisement:
[Part 23] Implementing Experience gain modifier
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 23] Implementing Experience gain modifier
- This topic has 3 replies, 2 voices, and was last updated 2 hours, 3 minutes ago by
Terence.
-
AuthorPosts
-
April 20, 2025 at 11:09 am #17963::
In Vampire Survivors, you can modify the amount of experience your character gains in several ways. One of them is the passive item Crown, which increases experience gain by 8% per level.
For example, if you have a Crown and gain 100 experience, you’ll end up getting 108 experience points.
Here’s how to implement it!
Inside PlayerStats.cs In the IncreaseExperience function: PlayerStats.cs
public void IncreaseExperience(int amount) { experience += Mathf.RoundToInt(amount * actualStats.expGain); LevelUpChecker(); UpdateExpBar(); }
This behavior is set to round the experience gain after the multiplication, but you can adjust it as you prefer.
Inside character data add these changes:
using UnityEngine; [CreateAssetMenu(fileName = "Character Data", menuName = "2D Top-down Rogue-like/Character Data")] public class CharacterData : ScriptableObject { [SerializeField] Sprite icon; public RuntimeAnimatorController animator; public Sprite Icon { get => icon; private set => icon = value; } [SerializeField] new string name; public string Name { get => name; private set => name = value; } [SerializeField] WeaponData startingWeapon; public WeaponData StartingWeapon { get => startingWeapon; private set => startingWeapon = value; } [System.Serializable] public struct Stats { public float maxHealth, recovery, armor; [Range(-1, 10)] public float moveSpeed, might, area; [Range(-1, 5)] public float speed, duration; [Range(-1, 10)] public int amount; [Range(-1, 1)] public float cooldown; [Range(-1, 10)] public float expGain; [Min(-1)] public float luck, growth, greed, curse; public float magnet; public int revival; public static Stats operator +(Stats s1, Stats s2) { s1.maxHealth += s2.maxHealth; s1.recovery += s2.recovery; s1.armor += s2.armor; s1.moveSpeed += s2.moveSpeed; s1.might += s2.might; s1.area += s2.area; s1.speed += s2.speed; s1.duration += s2.duration; s1.amount += s2.amount; s1.cooldown += s2.cooldown; s1.expGain += s2.expGain; s1.luck += s2.luck; s1.growth += s2.growth; s1.greed += s2.greed; s1.curse += s2.curse; s1.magnet += s2.magnet; return s1; } public static Stats operator *(Stats s1, Stats s2) { s1.maxHealth *= s2.maxHealth; s1.recovery *= s2.recovery; s1.armor *= s2.armor; s1.moveSpeed *= s2.moveSpeed; s1.might *= s2.might; s1.area *= s2.area; s1.speed *= s2.speed; s1.duration *= s2.duration; s1.amount *= s2.amount; s1.cooldown *= s2.cooldown; s1.luck *= s2.luck; s1.growth *= s2.growth; s1.greed *= s2.greed; s1.curse *= s2.curse; s1.magnet *= s2.magnet; return s1; } } public Stats stats = new Stats { maxHealth = 100, moveSpeed = 1, might = 1, amount = 0, area = 1, speed = 1, duration = 1, cooldown = 1, <span style="color: #32CD32;">expGain = 1,</span> luck = 1, greed = 1, growth = 1, curse = 1 }; }
Now make sure to check the values in your character’s scriptable object
Finally, lets create the Crown Item Passive Data! Create a Passive Item Data, name it Crown Passive Item and then set these stats
for the other levels just copy level 2 and change the name accordingly!
has upvoted this post. April 20, 2025 at 11:58 am #17964::@jukers thank you for sharing this.
Instead of adding a new
expGain
variable, you can use the existinggrowth
stat, which affects experience gain: https://vampire-survivors.fandom.com/wiki/GrowthThis means that we use the same code that you have, except that we use
growth
instead ofexpGain
.public void IncreaseExperience(int amount) { experience += Mathf.RoundToInt(amount * actualStats.growth
expGain); LevelUpChecker(); UpdateExpBar(); }Thank you for sharing this! I didn’t notice that I forgot to implement bonus experience gain.
- 1 anonymous person
April 21, 2025 at 1:17 am #17971April 21, 2025 at 8:37 pm #17972 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: