Lightning pickup!

AJ Studios

I successfully created 4 pickups, Basic Fire, Rapid Fire, Ice Fist & Lightning Ray. I am able to pick them up except the Lightning Ray. I’m not sure what I did wrong but I follow the same steps when creating all the pickups. Below is a video that better explains this.

  • AJ Studios replied

  • Nathan Lovato replied

    In your lightning pickup scene, if you select the lightning pick up node, you can see in the inspector that the pickup scene is not set.

    This causes the character to not get a spell upon touching the pickup, which is why the hands disappear: the previous spell (the rapid fire in your video) gets freed (the nodes get deleted) and nothing replaces it.

    The error when you try to loot the next pickup is due to the fact that the code is trying to free a spell but there is no valid spell node to free as the previous one was already freed and not replaced.

    Great job on making the 4 spells!

    1 love
  • AJ Studios replied

    Yes that was the problem, thanks for your assistance! I have a couple of questions that surfaced when I was creating a new Spell. I will list them below:

    1- How can I make the 'for loop' work as intended?

    2- How can I fix a small delay on the rapid fire bullet?

    3- How can I change the color of a different variation of the same bullet? - Example: BasicFire bullet color is different than the RapidFire bullet color.

  • Nathan Lovato replied

    Hi! You've been busy! Great progress :)

    Here are the answers to your questions:

    1. Shooting in a cone spawns one more bullet than expected

    The reason you are shooting one more bullet than expected in your code is that you first call the parent implementation of the shoot function, which shoots one bullet. Then, you shoot an extra couple of bullets using your loop. So this code will always shoot one more projectile than you would like.

    My recommendation would be to create a new function dedicated to shooting several bullets in a cone (for example, shoot_in_cone()). This new function can have brand-new logic that shoots three bullets or, if you want to reuse the shoot function, you could rotate the cannon and call the shoot function three times in a loop.

    2. The first bullet of the rapid fire spell has a longer cooldown

    Looking at your code, the reason you observe this behavior is that you don't change the cooldown timer's wait_time until after shooting the first bullet. The shoot function starts the cooldown timer and uses the default duration of the cooldown timer set in the spell scene. It is only the next time you shoot that the value change will be taken into account.

    To address this issue, move the line that changes the cooldown timer's wait time to the _ready() function, so that the cooldown timer's duration is changed before shooting the first time.

    3. Changing the color of individual bullets

    There are quite a few possible solutions here.

    Given how the game is set up, the simplest solution here is indeed to make different bullet scenes, and you can absolutely use inherited scenes if all you want to do is tweak the color, or even change the bullet sprite for a different look. This allows you to leverage the Godot editor and preview changes without running the game.

    With more experience, if you worked on a commercial game, a common solution would be to create a more complex bullet scene and script with lots of exported variables you could use to quickly change the look and effect of a given bullet. Designers in your team could then quickly create a wide variety of projectiles, and you can also modify these projectiles via code. But this approach requires a lot more code and is a bit beyond the scope of this course. I'm just mentioning it to hint at how we might do things in a more professional or team setting.

    1 love
  • AJ Studios replied

    Thanks Nathan for your response! I’m viewing this as I’m getting ready for work (although I want to stay home and work on this…lol). I will start woking on it as soon as I get a change and will reply back with the results. 

    - Your first response is probably the most challenging for me but I like that since it gives me room to test, play and come up with solutions on my own.

    - Your second response makes a lot of sense although I would’ve never thought of that, so thank you for the suggestion.

    - Your third response (the second part) left me thinking but I will stick to the 1st recommendation of creating a new bullet scene or, an inherited scene. The second part does sound really complicated although very interesting. 

    And yes, I’ve been busy, as I was waiting for a response I was also working on “Creating the 1st Mob” section. The more I get into it the more exiting it gets :)

  • Nathan Lovato replied

    Best of luck with these challenges, and I'm glad to hear you're enjoying the mob part!

  • AJ Studios replied

    Thanks for your help, I was able to:

    1- Shoot 3 bullets in a cone instead of 4. I did as you suggested and created a new function with new logic.

    2- Fix the issue where there was a delay after the first bullet in the rapid fire spell.

    3- Change the color of the bullets individually.

    I created more pickups and all worked as intended except for my last challenge. I created a variation of the lightning pickup but is not working as intended. More details in the video below:

  • AJ Studios replied


    I was able to fix the issue with the lightning bullet not moving forward as it was spinning. I encountered a new behavior and I would like to understand why it’s happening. Watch video below for more details. 

  • Nathan Lovato replied

    Great job on getting this working!

    What's happening in the game when you hit something, according to the code, is that the destroy animation plays. And the destroy animation leaves some time before actually fully destroying the bullet node. This delay gives time to the particles to display and play their animation. During that time, unless you explicitly hide the sprite, it will stay visible. So two options:

    1. You could call your lightning sprite's hide() function (or set its visible property to false) right below the line that plays the destroy animation.

    2. You could update the destroy animation to make the sprite invisible if it's not already the case.

    I hope this helps.

  • AJ Studios replied

    I see, thanks for that. I think I’m getting a better understanding of how this works. I went ahead and set the visibility property to false and this solved the problem.

    sapearing solved.png

  • Nathan Lovato replied