Section 11 - Share Progress

Section 11 Demo

Mixed feelings about the state of my RPG Project right now. I love the level-up effect I made, and the hit effects from my arrows and pickups are pretty much how I want them. The player can now at least see their health/xp/level/enemy-hp, which really does help a lot, and the new Firebolt projectile and hit-effect look awesome.

However, there are some glaring problems that I didn’t really notice until actually playing it thru on the uploaded site. Most of them seem related to changing scenes or save/load.

  • Because the game recalculates save-data and turns xp into levels whenever a scene is loaded, it shows a lot of annoying things every time you enter a scene: level-up and enemy-death animations, a typo I made where it increases the player’s health thru every portal. (I fixed this already)
  • For an unknown reason, if you save with ‘S’, then kill an enemy, then load with ‘L’, it loads positions and most things correctly, but the enemy is still dead. (not the same as Lecture #138 where enemies came BACK to life on load),
  • If you enter the scene from a portal, move around/attack/etc, then save with ‘S’, reloading with ‘L’ brings you back to that save point. However, if you reload the game, it reloads with health/dead-enemies/etc correct except that it resets the player’s transform to the portal instead of the ‘S’ save point.
  • My biggest issue was trying to create a cool slashing effect on the sword weapon. I tried many ways to do this, and they were all awful.
    • Apparently, Unity refuses to tell your weapon its world coordinates, so if you try to spawn a particle effect off of the weapon, it cannot find the location, and spawns it in relation to world 0,0,0. After a couple days of fruitless effort, I made a nasty hack that forced it to the right position, but getting the rotation correct was more than I could manage.
    • After giving up, I tried simply adding a trail to the tip of the sword like we did at the back of the arrow, and put the effect into a SerializedField in my new Melee.cs component on the weaponPrefab. In Awake() and Start(), I can access the trail and set swingTrail.emitting = true/false and modify it any other way I could think of without any problems. However, it seems to lose the reference to the trail because it will set the value of some magical, non-existent trail instead of the actual trail… It will tell me it is setting those values, I can print their values to the console, but the trail doesn’t change from what it was at the end of Start(). If I select the sword at runtime, the trail effect is still there, but it isn’t being changed by the code.

TLDR
I am not sure which of these might be something addressed later and which will not, so I am continuing on with Section 12 for now. If anyone has any insight on any of these issues, I would love feedback. Otherwise, enjoy the Firebolts and LevelUp animations!

Better late than never … :sweat_smile: . I apologize for resurrecting this old thread. You made some good points, and there was no answer, so here goes my take on those things. Maybe it will help someone else when they get to this point.

Because the game recalculates save-data and turns XP into levels whenever a scene is loaded, it shows many annoying things every time you enter a scene: level-up and enemy-death animations, a typo I made where it increases the player’s health thru every portal. (I fixed this already)

I don’t know how you set up your Level Up Prefab/particle system - but my best guess would be: you have “Play on Awake” set to active. This would trigger the animation every time you would start the game. I have no issues with mine, and there’s no code in the course that would trigger the animation on load.

The enemy death animation is indeed a problem. The way I fixed this issue was this.

In Heath.cs - Die() function - I’ve added a bool parameter to the function that checks if you already played the animation. If yes - if simply jumps to the last frame of the animation instead of playing it

        private void Die(bool alreadyPlayed)
        {
            //if the target is already dead, don't play the animation again
            if (isDead) return;

            isDead = true;
            
            //if we already played the animation and we are just reloading the level, skip to the last frame
            if (!alreadyPlayed)
            {
                GetComponent<Animator>().SetTrigger("die");
            }
            else
            {
                GetComponent<Animator>().Play("death",0,1f);
            }
            GetComponent<ActionScheduler>().CancelCurrentAction();
            GetComponent<Collider>().isTrigger = true;
        }

This bool allows me to tell the saving system that the animation was played the first time, and we just want to reload the scene. Here’s how my RestoreState() looks like

        public void RestoreState(object state)
        {
            healthPoints.value = (float)state;
            if (healthPoints.value==0)
            {
                Die(true);
            }

        }

And I can trigger the animation in TakeDamage by calling Die(false)

if (healthPoints.value==0)
            {
                Die(false);
                AwardExperience(instigator);
            }

For an unknown reason, if you save with ‘S,’ then kill an enemy, then load with ‘L,’ it loads positions and most things correctly, but the enemy is still dead. (not the same as Lecture #138where enemies came BACK to life on load). If you enter the scene from a portal, move around/attack/etc., then save with ‘S,’ reloading with ‘L’ brings you back to that save point. However, if you reload the game, it reloads with health/dead-enemies/etc. Correct, except that it resets the player’s transform to the portal instead of the ‘S’ save point.

I had the same issue, and it seems the “Load” functionality is a bit different than that of Play Game (in the editor). What I mean by that: the load acts as a quick load without first unloading any of the elements, while Play Game is the full “Load” since it calls “StartCoroutine(LoadLastScene());.” So my solution was to change the load code to the full coroutine, which fixed most of my issues.

My biggest issue was trying to create a cool slashing effect on the sword weapon. I tried many ways to do this, and they were all awful.

The way I made my sword slash was to parent the slash effect to the player. Since the effect you want to achieve is relative in distance to the player and its forward direction, it made sense to me, to have it there and trigger it when needed. I had to tweak the Particle System - Start Delay to get the timing right. Here’s how it looks

Your idea of using Trail Renderer would work just as well, but you would need to parent the effect to the sword prefab instead. That way you would use the animation/motion of the object to create the effect. I tried something similar, however, the sword was “emitting” all the time and made a trail as I was running with the sword in hand.

Hope this helps.

1 Like

Privacy & Terms