For Godot 4 users: - func _unhandled_input(event: InputEvent) -> void: is now simplified to func _unhandled_input(event): - export (PackedScene) var Bullet is now @export var Bullet :PackedScene - Position2D is now Marker2D - onready is now @onready Also if you haven't solved your blurry textures yet, you need to go into the Sprite2D Inspector. Under the Texture tab charge Filter from Inherit to Nearest.
@@jmbiv_dev Thanks for the great tutorial series, I've learned a lot! As I've gotten deeper in the series the less I've run into these syntax issues so hopefully these help people keep going through the series 👍
I'm using 4.2, instance() becomes instantiate(), feel free to take this into your comment @ByteChompGames , besides that, your comment saved me a bunch of time! Thanks
私は日本人ですが、貴方の解説が非常に丁寧なため翻訳字幕でこのチュートリアルを完了できました。 jmbiv殿、ありがとうございます。 I'm Japanese, but your explanation was so thorough that I was able to complete this tutorial with translated subtitles. Thank you, jmbiv.
Participating in my first Godot Wild Jam at the moment. In preparation I had purchased a course on Udemy to try and learn stuff, but the teaching style and content you go over has been infinitely more useful. Great work!
Thanks so much for the tutorial, been trying to get myself into Godot and this was a perfect find to get me started on making something functional. Can't wait to finish more of your series.
Thanks, I appreciate it! Glad you find it helpful. Yea, I had to take a break unfortunately over the last month or two since I started grad school this fall. Now that I've gotten into a bit of a routine videos should be coming out more regularly though - new one this Wednesday!
Sorry for some of the weird edits/cuts in this one - video editing software that I use was acting up. Hope you enjoy! Let me know any suggestions or specific things you'd like to cover in future videos.
Before finding this tutorial, I was working on a quick shooter test, but couldn't figure out why my instancing wasn't working. At about 12:30, when he showed him dragging the Bullet.tscn into the slot in the Inspector, everything clicked. I will definitely keep watching this series, but this was the biggest "a-ha" moment of my life. Nice video!
It's a really helpful function, and important to use because it only captures input that nothing else has handled up to this point (which helps reduce the same input being processed in multiple locations).
This is the best. I started learning Godot and I am passionate about game development and this career; this series gave me a boost and really helped me understand the basics. Thanks a lot!!🥰❤
It was really bugging me we dont get autocomplete for bullet_instance, so I dug into it. The reason is because the editor does not know the type of bullet_instance, so it cannot give us code completion suggestions. To solve this we can either A) give it the Area2D type: var bullet_instance: Area2D = Bullet.instance(), and this will give us suggestions for anything in Area2D like position, rotation, etc. Or B) give our Bullet a custom type with class_name Bullet in Bullet.gd, then var bullet_instance: Bullet = Bullet.instance(). This will give us access to everything in the parent class (Area2D), as well as custom methods and properties like speed. Hope this helps someone!
Thanks for leaving this note! We do a lot more explicit typing as they progress but not always as much as we should early on in the series. I'm sure others will find this helpful!
Thanks so much for the super thanks! I really appreciate it, and am so glad that these videos could be helpful for you. Absolutely, more tutorials coming! I've been doing a lot of work in Godot 4 and hope to have some exciting stuff coming soon.
Hey! I'm working in godot 4.0 and the code at 11:50 doesn't seem to work for me. I am getting the error message Unexpected "Identifier" in class body. What should I do to resolve this?
In Godot 4.x, the syntax for export variables has changed. So, previously it was: export (PackedScene) var bullet But now export is an annotation that uses the @ symbol. You also don't give a type hint, you just explicitly type your export variable. So, altogether, it should now look like this in 4.x: @export var bullet: PackedScene Hope that helps!
First off ! Thanks for making this tutorial. I was looking for someone who'd actually help with the coding process. I'm having a bit of a hard time with auto completing some lines. func unhandled_input always gets filled in with func _unhandled_input(Event) : instead of: func _unhandled_input(event: InputEvent) -> void: is there a reason why it does that ?
Great tutorial! I'm trying to implement this into a 3d game throwing snowballs. I got it to work until the snowball spawns in the hand. I tried doing Vector3 instead of 2 and now every time I shoot, it spawns in a straight line not moving. Any tips?
bullet direction can use another way: when pawn a bullet , bullet.lootat(get_global_mouse_position) once. then velocity = vector(1,0).rotated(rotations)....
This series is amazing! sorry if this is a bit of a noob difference but what is the difference between using event. vs input.? is event. exclusive for unhandled input or some other reason. thank you for the amazing videos :)
Thanks for saying that, I'm glad they've been helpful! And no worries at all, it's a good question. You're pretty much correct - "event" is exclusive to functions like "_unhandled_input". It's better to use "event" than just "Input" because then we are only responding to the specific input event that called the _unhandled_input function. This is why we respond to input in _unhandled_input and not _process, for example, because doing it in _process would call our input handling every single frame. We don't need to handle input every frame - we only need to handle it when the player actually provides some input, so it's a lot more efficient. Hope that makes sense!
Godot 4 autofills a few things different, and I don't notice a difference when running each line. But for example: He will have: func _unhandled_input(event: InputEvent) -> void: GD4 will autofill func _unhandled_input(event): Is there any significant difference? I'm changing everything to be the exact syntax he uses just for consistency sake rn... Additional side note: another way to get @onready var end_of_gun = $endOfGun is to drag endOfGun and then hold ctrl just before releasing.
Great question! The difference you see in my code isn't because of Godot 3 vs. Godot 4, but because I have an editor setting turned on that automatically adds static types to Godot's autocomplete. Static types aren't required (which is why your code works totally fine without them), but they are super helpful - and, in Godot 4.x (but not in 3.x), using static types can actually make your code run faster. I haven't double-checked this in Godot 4.x, but I believe the path to turn on the setting is this (from the Editor dropdown of the top menu bar): Editor > Editor Settings > General > Text Editor > Completion > Add Type Hints Not required but highly recommend turning it on and trying to use types in your code whenever possible!
I thought my shooting wasn't working, I couldn't see the bullets coming out at all. Turns out I can only barely see them when I set the bullet speed to 1. I have it in the physics_process function too so I don't know why it's still super fast.
The first potential issue I can think of is that you might not be normalizing the direction vector you're multiplying with your bullet's speed - can you check and make sure you're doing that?
@@jmbiv_dev I must've missed that and I can't find it in the video, is that in the bullet's script? The only thing I normalized so far was the movement direction to prevent the faster diagonal movement with the movement_direction=movement_direction.normalized()
@@ISmellMopWho You're right, not sure that's in the video. Can you make sure you're doing your code in 'physics_process' and not in 'process'? That could potentially be why it's moving so fast. If that isn't the issue, if you hop in the discord server I can help you debug further.
Glad it's helpful! If we didn't include a direction parameter, we would have no way to tell our bullet which direction to go in. That's why we have to include that parameter (which is what you see within the parentheses!). Hope that helps!
Hello, I have a simple question When the player moves, the bullets become inactive and come out from different places, and when the player moves, the bullets move with him. Do you have a solution?
So the whole video is straight forward and it helped alot but i am trying to make a game where you use the buttons to aim your shot instead of the mouse. In player.gd, line 42 - line 44 are for assigning where the bullet will go corrisponding to where the mouse is. Is there any way you can show me how to click a button so the bullet shoots to the right instead of where the mouse is? Thanks
Glad it was helpful! And good question. I'll give a quick answer, but can you give more context on how your game works? Does the player move at all, and do you want the player to be able to shoot anywhere or just a few fixed directions, like left/right/straight? Instead of using direction_to(), I would probably just set the rotation_degrees property on your player. So if the user hits the button to go to the right, do rotation_degrees += 30 (or some number that works) and then shoot. Is that what you're looking for?
The game i am making is 2 wizards get put on a feild and they have to kill the other player while dodging the other players projectiles. So far, i have the bullet spawning in at the wizards location but i just need the bullet to take off (shoot) when a key is pressed which i am having trouble doing. Once i know how to get the bullets to move, ill make it so the player can shoot up, down, left, or right using the rotation_degrees += 30 that you suggested.
Why do we export the packed scene from the player script? It’s seems unintuitive to me. Shouldn’t we export the scene from the bullet scene itself? Little confused haha. Thanks in advance!!
Sorry for the delayed reply! You're right, though, that the player script isn't really the best place to export the packed scene from. The issue in this video is that we don't really have any other place to export it from... yet! We don't have a separate weapon node/system built out, at least in this video. In just a few more videos we'll come up with a much better and intuitive system, so stay tuned 🙂
add_child thing lags me up. i dont know why. but when i manually put the bullet scene in the player it dont lag. so i guess that fix it xd. i dont know if its only me tho. lol
That's weird that add_child causes some lag. It shouldn't ever really with just one node, even on a super old computer. Manually adding the bullet scene to the player and hiding it until you use it is a good workaround though.
you really deserve more subs and support nice vid! ur probably gonna help a lot for my own game, lots of similar shooter mechanics doe its not the main theme edit also the bullet doesn't move for me and I retyped the code 3 times so please help
Thanks for saying that, I really appreciate it! And nice, that's awesome, best of luck with your game. Are you seeing any error messages? If you try moving your slightly farther away from your player's body, do the bullets appear now? Sometimes they can collide with your player if they are too close. Let me know if that helps. Otherwise, feel free to join the discord server and I can help you more.
Try moving the gun a little farther away from the body of the player/unit that’s shooting it - sometimes the bullet instantly collides with the body if it’s too close
Great question! the ":float" is declaring what type of thing delta is - it's part of Godot's static typing system, which is really awesome and worth learning about. I've got a video with more info you can check out here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2K150BYhQ_8.html
That probably means that, wherever you're getting a reference to "object," the "object" in question is null. Try making sure that "object" is actually being set to a real thing, and if you're still having trouble we can help more in the discord server!
At line : var direction_to_mouse = Bullet_instance.global_position.direction_to(target).mormalized() i'm geting this error : Invalid call. Nonexistent function 'mormalized' in base 'Vector2'. Cam someone explain me how to fix it?
i spent a while(like, 10 minutes) trying to figure out what i did wrong, and it turns out i misspelled global_position as global_positon. currently crying in the corner
Sorry you're having trouble! I'm not sure what might be going wrong just off your comment - try following the next video and see if that helps. Otherwise, if you join our discord server, you can post some images of what's going wrong and that will make it easier for us to help you!
@@jmbiv_dev actually i didnt follow these series,im new and just came for adding shooting mechanic for my game, probably thats why it didnt work for me, right now i use raycast, but when i want to make a more detailed shooting mechanic, i will come and follow these series, thanks ! watching you screen change tutorial rn :D
@@rbcodder1701 ah, gotcha! cool, hope that you've had a good experience learning Godot, and like I said, we're here to help in the Discord server if you ever need it!
Is that something you're seeing in your own game after this video? If so, try watching the next part (#4) and see if it's fixed there. We clean up some issues with our shooting code and do some other fixes there. If it doesn't fix it though, then just post a comment there and I can help.
This is because of the _on_Bullet_body_entered() function in our bullet script. It's set to only handle collisions with physics bodies that have the "handle_hit()" function. If you want it to collide with tiles in your tilemap, you'll have to also add some handling for that within that body_entered function. Hope that helps!
Export PacketScene var bullet is giving me this error. My Gofot seems to be in a whole different launguage, expecting different terms that yours. here is the error - Expected a constant expression
This might just be a typo in your comment here, but make sure it is "Export (PackedScene)" instead of "Export PacketScene" Other than that, the "expected constant expression" error often occurs when you forget to add a ":" to a function or a type or some other value. Take a close look at the line with the error and make sure you don't have any syntax errors. If you still have trouble, join our community discord (link in the description) and I can help you further!
For some reason, my bullet spawns but does not carry out its code. It just stays in the same place. Can you help me? Also, I found these tutorials really helpful. thanks!
Have you placed any breakpoints or print statements in the code that gives your bullet velocity? If not, try doing that and make sure you're actually getting a velocity passed in to it.
@@jmbiv_dev Sorry to necro post but I'm having the same issue, started this video from scratch twice and still the same result, says the function 'set_direction' is nonexistent in base 'Area2D'. edit: joined the discord and immediately got the answer to my problem :) if anyone else stumbles upon this, make sure your bullet script is tied to the node (oops)
when i add bullet_instance.global_position=end(yeah i put that name on var).global_position i dont see any bullet or any if i remove this child appeas i tried bullet_instance:Area2d and create class name i didnt work any solutions EDIT:FIXED just add get_tree().get_root().addchild
Good question - you absolutely can just use _process and multiply by delta, but it’s much less efficient because now your code is running every frame (60 to even 240+ times a second) instead of just running every physics step (usually like 8 times a second), so you’re doing dramatically more work that you don’t really need to do. There’s no real reason not to use physics process anyway - it’s a helper meant specifically for operations that will move a body or area and other physics objects, so by using physics process for those operations, it sets a standard/makes it easier to find those in a given script if you’re looking. There might be reasons to use regular process that I’m missing here, but 99% physics process is the better option.
Also I’m forgetting another important use - for things like rigid bodies, which are totally influenced by the physics system and not manual adjustment, physics process is the only function synced to the physics engine, so it’s the only function where you can reliably get a rigid body’s given position or scale, etc, at a specific time. So especially for rigid bodies even more than areas or kinematic bodies you want to use physics process.
hey Jmbiv, for some reason, my bullet manager is not doing anything, I printed code on player and it shows up area2d being spawned, but it doesn't shows up any print from bullet manager.... and I have all the code together :S
Hmm, that’s weird - can you join the discord server and post some pictures of your code (especially where the bullet signal is connected to the bullet manager)? We can help debug there.
I’m a little late to the party but I keep getting an error: Invalid call. Nonexistent function ‘set_direction’ in base ‘Area2D’. Any help would be very appreciated!
Did you manage to resolve this? Check that your Bullet node has a script attached to it. You can see that if you open your Bullet scene, at the parent node of Bullet there should be a script icon next to it. If the script is missing, just re-add it.
It might be because your bullet variable is null or is set to something that is not a PackedScene (a .tscn file) - can you make sure that you've dragged the correct thing into the editor for the bullet variable?
Man... this tutorial simply does NOT wish to play nicely with Godot 4. I figured "I'll just translate it to gsl2" but I'm getting a new error every minute of tutorial. I've solved like 3 of them so far and right now the major error I'm getting is: bullet.instatate.set_direction(direction_to_mouse) Underneath the bullet script is throwing the error "Invalid Call, Nonexistant Function "Set Direction" in base "Area2d" I've asked on the discord and everybody seems stumped I wish someone could redo this tutorial for godot 4, very frustrating when 90% of the material on youtube is obsolete
Hey! I am also having problems getting this tutorial to work in godot 4. How did you get the packed scene at 11:50 to work? I'm sorry that I can't really help with your problem cause I'm just as stumped as you are.
@@MossSkullGames The fix is to change this line of code to "@export var bullet: PackedScene" but you're just going to encounter more errors about 30 seconds of video from now xD If you figure out my problem, do let us know