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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17963
    Jukers
    Level 9
    Bronze Supporter (Patron)
    Helpful?
    Up
    1
    ::

    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

    Crown scriptable object (0.08 exp gain stats)

    for the other levels just copy level 2 and change the name accordingly!

    has upvoted this post.
    #17964
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    1
    ::

    @jukers thank you for sharing this.

    Instead of adding a new expGain variable, you can use the existing growth stat, which affects experience gain: https://vampire-survivors.fandom.com/wiki/Growth

    This means that we use the same code that you have, except that we use growth instead of expGain.

    public void IncreaseExperience(int amount)
    {
    
        experience += Mathf.RoundToInt(amount * actualStats.growthexpGain);
    
        LevelUpChecker();
        UpdateExpBar();
    }

    Thank you for sharing this! I didn’t notice that I forgot to implement bonus experience gain.

      1 anonymous person
    has upvoted this post.
    #17971
    Jukers
    Level 9
    Bronze Supporter (Patron)
    Helpful?
    Up
    1
    ::

    I completely missed that! going to update the post!

    has upvoted this post.
    #17972
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    @jukers you’re awesome my friend. Thank you for contributing to the forums.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: