Turret rotate and elevate toward a target - Godot 3D Tutorial - Target tracking - Code and Math

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • #gamedev #godot #godot4
    00:31 Turret Components
    02:13 The Math
    04:38 The Code
    12:47 Scenes
    17:26 Project download and outro
    I'll show you how to create a 3D turret in Godot that features:
    - Independent rotation and elevation
    - Target tracking
    - Customizable tracking speed
    - and the turret works at any orientation (or even while moving) meaning you can slap it on the side of your ugly ass capital ship with no problem.
    You can download the project here:
    github.com/nea...
    Or here:
    drive.google.c...
    My project is loosely based on code from here:
    github.com/Ind...
    • Modular AI Turret - Fr...
    I was also assisted by this resource:
    math.stackexch...

Комментарии • 24

  • @NealHoltschulte
    @NealHoltschulte  Месяц назад +1

    All code is available on github: github.com/nealholt/TurretGodot
    Check out my other videos on target leading ruclips.net/video/ZjMjxj_blMQ/видео.html
    and compensating for bullet drop: ruclips.net/video/Hzgo5Jr2gI4/видео.html

  • @pascalcasier959
    @pascalcasier959 10 дней назад +1

    Thank you, very helpfull

  • @mewingmonkey-q4g
    @mewingmonkey-q4g 2 месяца назад +2

    Thank you u just got a new subscriber

  • @tehpyono2203
    @tehpyono2203 3 дня назад +1

    Might not be exactly relevant, but if I import a 3d model from say Maya, does the turret need rigging for it to move like what you shown at the start? (turret elevation and rotation) Also, I assume any animations done would not be useful in this case as the turrets don't exactly "play" any predefine animations unless you make one for firing?

    • @NealHoltschulte
      @NealHoltschulte  3 дня назад +1

      Not having imported models from Maya, I'm not sure. You definitely need the head + body node3Ds to give rotation instructions to. And I did not add any animations to the turrets demonstrated here.

  • @mattjones8089
    @mattjones8089 Месяц назад +1

    Insanely helpful. I was really unhappy with many turret tuts I'd found and this one was not just what I needed, but so thorough in the explanation. I'm still wrapping my head around some of how it functions, but I have it implemented nicely. My Corvettes now have ferocious CIWS stations to deter you from casually blasting in their bridges, Gundam-style.

  • @mewingmonkey-q4g
    @mewingmonkey-q4g 2 месяца назад +2

    u helped me so much ur insane

  • @mimadm4832
    @mimadm4832 2 месяца назад +1

    Hey man, really great video, I am a noobie on coding and I have a question to ask, I am trying to implement a lock-on system to my character. Would I be able to use this code for that function? Or would there be a system that would fit my needs?

    • @NealHoltschulte
      @NealHoltschulte  2 месяца назад +1

      Start simple and see if the look_at function meets your needs, but if not, I can certainly see this tracking code for the turrets being applicable, depending on what precise behavior you're hoping for.

  • @edsavage2880
    @edsavage2880 2 месяца назад +2

    This is great! But it seems to work on the opposite basis of Godot's -z = forwards convention - all my turrets are pointed in the exact opposite direction! Any way to fix?

    • @NealHoltschulte
      @NealHoltschulte  2 месяца назад +2

      Yeah, sorry about that. I think I put all my turret "heads" on backwards when I first made them and then instead of doing the obvious fix of righting the head, I negated z in the code. Play around with negating or changing the model and you should eventually get it sorted out.

    • @edsavage2880
      @edsavage2880 2 месяца назад +2

      @@NealHoltschulte Sorted - thanks! For others - I negated both instances of global_basis.z, and both the variables final_y and final_x. This alongside reversing the head rotation clamp solved the inverted direction. Great tutorial :)

    • @octagear
      @octagear 2 месяца назад +1

      Big Thanks to both of you, i was wondering about this as well but my solution left the turrets jittering like crazy

  • @thalesr6916
    @thalesr6916 4 месяца назад +4

    Awesome tutorial! I love to learn how to use math in games, especially 3d. I learned a little about vectors and dot product and now I'm using it everywhere in my code lol

  • @brennennen1761
    @brennennen1761 4 месяца назад +2

    Thanks for thorough tutorial and documentation!

    • @NealHoltschulte
      @NealHoltschulte  4 месяца назад +2

      You're welcome! I hope it's useful to people.

    • @brennennen1761
      @brennennen1761 4 месяца назад +1

      @@NealHoltschulte Well it's for sure useful to me! I'm making a security camera that's got an armature/rig and can track a player. So it's slightly different in that I am working on bones instead of nodes, but other than that, it's pretty much the same. I originally tried to use the "look_at" and "looking_at" functions and just multiplying the axis I don't want to modify by 0 to "lock" axises. Those functions have some very specific requirements around the axis orientations that seem to not work well with bones though (ex: +Z or -Z needs to be forward and there needs to be a fixed well known global pos up axis).
      In my experience with rigging (which is limited and I might be missing something), your bone axis orientation is dependent on the bone chain, so you can end up in scenarios where +Z and -Z being forward just doesn't work and there isn't a good well known global position up axis, which makes makes those "look_at"/"looking_at" functions very difficult to use and debug issues with. The lower level approach taken by this video, and the easy to read code is exactly what I've been looking for. After this security camera, I plan to try and get this same thing working on a human's head/neck bone chains to try and get some character face tracking too, so yea I think this video helped me a boatload! Thanks again!

    • @NealHoltschulte
      @NealHoltschulte  4 месяца назад +2

      @@brennennen1761 I've not worked with bones before, but I'm happy this was helpful. I had a similar frustration with other tutorials telling me what to do, but not why and I was immediately stuck when I tried to do something slightly outside the box, so I wanted to make something that wasn't so rigid once I figured out how the hell to do it.

  • @arekkubiak5957
    @arekkubiak5957 2 месяца назад +1

    It makes sense that such a detailed turret tutorial comes from a House of the Dying Sun veteran :] More tutorials related to this kind of games would be appreciated

    • @NealHoltschulte
      @NealHoltschulte  2 месяца назад +2

      @@arekkubiak5957 I’ve got a shitty HotDS clone working in Godot! When life gets less busy I’ll make a video and put it out there :)

    • @arekkubiak5957
      @arekkubiak5957 2 месяца назад +1

      @@NealHoltschulte Ooo can't wait!