How to Make a Homing Missile in the Godot Engine: 2D guide

Поділитися
Вставка
  • Опубліковано 21 жов 2022
  • Preorder Node Essentials - Godot 4 edition: school.gdquest.com/products/g...
    Learn GDScript From Zero for Free: www.gdquest.com/
    📚 THE LINKS
    Download the demo project: github.com/gdquest-demos/godo...
    How to code ranged attacks in Godot: • How to Code Ranged Att...
    Intro to vectors for games: • Introduction to Vector...
    👥 CREDITS
    Video edited by Nesi: / nesiawesomeness
    💌 JOIN US
    Come chat on Discord: / discord
    Follow us on Twitter: / nathangdquest
    📝 CC-BY LICENSE
    This video is licensed under the CC-By 4.0 license: creativecommons.org/licenses/...
    You can attribute it to "CC-By 4.0 - GDQuest and contributors - www.gdquest.com/"

КОМЕНТАРІ • 47

  • @gillesroudiere541
    @gillesroudiere541 Рік тому +42

    The change variable should probably be multiplied by delta, otherwise the change is constant per-frame, and thus frame rate dependent

    • @gillesroudiere541
      @gillesroudiere541 Рік тому +7

      Ah and I forgot to precise, this is otherwise a great tutorial. Very well explained (and I love the thumbnail ^^)

    • @oskarwerner2164
      @oskarwerner2164 Рік тому

      What do you mean? Its multiplied in position variable

    • @gamer-x9
      @gamer-x9 Рік тому

      Can you explain why use delta and what it is

    • @ana_s
      @ana_s Рік тому +10

      @@gamer-x9 I hope it’s not too late, but anyways.
      Deltatime is the time passes from the previous frame to the current frame. This is essential for movement and other physics based calculations. Why is it essential? Let’s look at a scenario.
      Let’s say, you want to move a player 20 units (arbitrary unit) forward every second, if you just put 20, it means you move the player forward 20 units every frame or 1200 units per second. This is way more than we want. Because the game runs on frames instead of seconds, it would be impossible to convert speed to seconds, right? This is where deltatime comes in. It changes the speed from every frame to every second. If you move the player 20 units multiplied by deltatime (20*dt), it ensures you move 20 units a second. How? Well if your fps changes, from 60, and your game slows down, the speed stays consistent, if your frame took 1 second, it would be 20*1 (20*dt, note that dt is in seconds), which means 20 units since a second passed. If the frame took 2 seconds, it would be 40, which is consistent to our speed of 20 units/second
      If you don’t use dt, there would be problems in your game, like changing speeds on different hardware. Since fps is never consistent, this will result in very fast movement on higher fps and very slow movement on lower fps.
      Here, we have to multiply change by dt as the change will be frame-dependent, not second-dependent

  • @TheBryancrochet
    @TheBryancrochet Рік тому +1

    This gave me great examples to answer questions I have had for years! THANKS!

  • @nopens
    @nopens 6 місяців тому

    Thank you. I tend to open these videos, try doing the topic myself then watch your solution.

  • @abhinandansharmaaa
    @abhinandansharmaaa Рік тому

    BROTHER, YOU ARE THE BEST!!! You oooh really helped me!! THANK YOU VERY MUCH!

  • @hiranurgunesli5649
    @hiranurgunesli5649 Рік тому

    thanks a lot!!! so nice reverb

  • @nopeggep
    @nopeggep Рік тому

    Thank you, it works perfect!

  • @frost8077
    @frost8077 Рік тому +1

    The fast release is a cool function, kind of like how some missiles pop out of a tube before their rocket engine ignites.
    I'll have to make use of this code myself for a magic attack, as if the energy projectiles have to wake up after creation before pursuing their target. To add further function as to bothering with the mechanic instead of direct damage, I would make them explode after a few seconds, giving the enemy a reason to evade the projectiles, and maybe have the travel distance affect the amount of damage.

  • @danisob3633
    @danisob3633 Рік тому

    great vid!

  • @armanuki38911
    @armanuki38911 Рік тому +6

    Nice video, but what about a missile that has a limited angular velocity, so it can miss the target?

    • @PaulSpades
      @PaulSpades Рік тому +1

      i guess just check current direction vector against move_to direction for an angular range. if angle is out of range, keep current direction. maybe even disable the blast, though this example doesn't have a blast stage when hitting the target.

  • @davestomper3428
    @davestomper3428 9 місяців тому

    Cool information exactly what I need except is there away to make it so missile have a lower accuracy rate, also if enemies can shoot the missile down based on a percentage
    Sorry very new. To godot4. And trying figure this all out thanks again for any information

  • @DesignerOfManyThings
    @DesignerOfManyThings 6 місяців тому

    I wanted to add an item that can be picked up with a grappling hook, but I needed the item to track the player as they were both in motion, so I literally just used the first minute of the video to learn that code, and still haven't watched the rest 😂 thanks for the great content though, this was really helpful

  • @VoltitanDev
    @VoltitanDev Рік тому +1

    Question how would the homing missile work for multiple enemies especially when the player holds a button and when released fire upon multiple enemies like Zone of the Ender or Macross for example.

    • @gamedev_byhobby8872
      @gamedev_byhobby8872 Рік тому

      You can check if an enemy has a target already and don't let other missiles target it. Then the missiles would lock on to only untargetted enemies, shooting one missile to each enemy

  • @CariTauGan
    @CariTauGan Рік тому

    hello, could you make tutorial on how to make time rewind?

  • @razorback9999able
    @razorback9999able 6 місяців тому

    How can a homing missile continue working properly if the target dies mid-seek?

  • @fernandogutierrez4278
    @fernandogutierrez4278 5 місяців тому +1

    In principle what you do is fine, but this is the easiest part of programming. There are still more complex questions to evaluate regarding behavior, such as what happens if there are two targets instead of just one, what would the behavior of the missile be? What happens if the target is destroyed, what do the missiles do next, do they go to another target or do they stay put at the last position of the target?

    • @Gdquest
      @Gdquest  5 місяців тому

      These are mostly design questions I'd say. Code-wise in Godot the things you point out are small code changes on top of this base. In the future, I sincerely hope we have the time and funding to take this content a bit further and write extra sections on our website like "what if I want to add this?" For us at least it's not more advanced or complicated. It's just that all the little additions on top of the base that a video like this presents are only interesting to a relatively small subset of learners like you. The interests of people start to branch out.
      We help the most people right now by providing the foundations on lots of things and by building better tools for teachers and students then if we cover less ground but go in great detail.

    • @fernandogutierrez4278
      @fernandogutierrez4278 5 місяців тому

      @@Gdquest I understand, thanks for answering

  • @cozycodeyt
    @cozycodeyt Рік тому +3

    I picked up Godot earlier this year and just released my second commercial game on mobile, still can't believe that this game engine is free.
    By the way, the name of the game is "Rubi - 2D Rubik's Cube", you might like it.

  • @starbirds007
    @starbirds007 8 місяців тому

    How did you set the target??? Please, can anyone tell me about it.

    • @adriancaso3811
      @adriancaso3811 8 місяців тому

      At the top of the script I initialized the variable (so just 'var _target') Then in the EnemyDetector (Area2D with a CollsionShape2D attached to it) I just connected the _on_EnemyDetector_body_entered signal to the script. Inside of that function I put _target = body and that works well enough. (I also added an if-statement if body.is_in_group("enemies"): _target = body but this is only if you have other nodes that the area2D might pick up)

  • @ruumroom.
    @ruumroom. Рік тому

    Can you do one but for 3D ???

  • @Komradenter
    @Komradenter 2 дні тому

    This tutorials should be revisited and rwroted to godot 4 ..

  • @teo2805
    @teo2805 Рік тому +3

    Enemy AI states + steering tutorial please

  • @saveriov.p.7725
    @saveriov.p.7725 7 місяців тому +1

    the github link is broken

    • @saveriov.p.7725
      @saveriov.p.7725 7 місяців тому

      Please fix. Your code is busted for Godot 4 so it would REALLY help to get the rest

  • @pipeliner8969
    @pipeliner8969 Рік тому

    Didn't you use to have a channel on Odysee?

  • @akash0156
    @akash0156 Рік тому

    The gd script app can it's available in apk format

    • @omotayodavid9
      @omotayodavid9 Рік тому

      Yes, if you export for Android

    • @akash0156
      @akash0156 Рік тому

      @@omotayodavid9 is a apk file available somewhere so i can just download easily?

    • @omotayodavid9
      @omotayodavid9 Рік тому

      Oh, you meant if you could install it on an android device? Sorry. You can't. You can only use it on a PC.

  • @fiesesalien
    @fiesesalien Рік тому +4

    Video way to quiet. Easy +3db needed.
    Stay crunchy.

    • @Seedzification
      @Seedzification Рік тому +2

      audio is fine imo

    • @AspieGamer
      @AspieGamer Рік тому

      The audio is quite quiet

    • @danisob3633
      @danisob3633 Рік тому

      @@Seedzification nah i came from other videos and i had to turn it to twice as much volume to hear it. ofc its fine when the volume is set but its about keeping it inside some range of db so it fits with the rest of vids and you dont get jumpscared and then dont hear and then jumpscare

    • @fiesesalien
      @fiesesalien Рік тому

      @@Seedzification Headphone or constant audio level changing user? Of course it will be fine then.
      That's usual the deal with the average joe. They don't have a care in the world, happily turn knobs and that.
      And to be honest: Even on the lowest volume level I still could hear a mouse fart that sits in a quiet-room. On a different planet. Three universes away. That is: If I had my headphones or in-ears on.
      That's were "standards" come in. You can develope a standard or you don't. You either make something for "everyone" or you gonna piss of the neighbours of some unfortunate soul that forgets to turn their volume down again after listening to a much quieter video.
      Stay crunchy.

    • @TheBryancrochet
      @TheBryancrochet Рік тому

      sound was spot on for me.
      It would be pretty hard to sound balance for everyone.

  • @SovereignVis
    @SovereignVis Рік тому +1

    Interesting, but a very unrealistic missile. The missile turns way too sharply, so I think you should have made it take longer to turn. Most missiles don't have a seeker head with 360 degree vision. Having a big circle around the missile to detect targets is just silly. So it would have been great if you showed how to add a cone instead of a circle, onto the head of the missile to give a more realistic like seeker head. Also having the missile just always turn to aim at the target is horribly inefficient, so would have been great if you could have also shown how to give the missile some form of proportional navigation guidance. But aside from all that, nice video.😅

  • @SULTANVIDEOGAMES
    @SULTANVIDEOGAMES Рік тому

    @export_node_path(Node2D) var _target_path
    @onready var _target_node: Node2D = get_node(_target_path)
    var speed: = 150.0
    var rotation_speed: = 1.0
    func _process(delta: float) -> void:
    var angle: float = position.angle_to_point(_target_node.position)

    transform.origin = transform.translated_local(Vector2.RIGHT * speed * delta).origin
    rotation = lerp_angle(rotation, angle, rotation_speed * delta)