I know that I'm a bit late with my reply, but heck - it might help someone reading this in the future. I LOVE Tom's tutorials, but you must know that theres quite a lot of quality tutors beside Tom. My personal favourites: "Game Development Center" - aimed at Diablo style rpg's and networking "Garbaj" - Just like Tom, he's mainly into FPS 'Rungeon" - a fairly new channel, but damn that guy is a gem. THE best platformer tutorials I've seen so far! "Heartbeast" - zelda-like (or ratherHyper light Drifter- like) arpg tutorials, and much more! "KidsCanCode" - This guy is a Wikipedia of Godot. Quality stuff! And these guys are just my top pics- I'm sure there's even more quality content out there. Hope that these references will help someone, as these tutors (Including Tom, obviously) helped me )
Hello someone could help me every time I pull its me but the error code 'raycast.is_colliding () null instence so here is my script tell me the error that I made please extends Node class_name Weapon export var fire_rate = 0.5 export var clip_size = 5 export var reload_rate = 1 onready var raycast = $"../Head/Camera/RayCast" var current_ammo = clip_size var can_fire = true var reloading = false func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: # fire the weapon if current_ammo > 0 and not reloading: print ("Fired weapon") can_fire = false current_ammo -= 1 check_collision() yield(get_tree().create_timer(fire_rate), "timeout") can_fire = true elif not reloading: print("reloading") reloading = true yield(get_tree().create_timer(reload_rate), "timeout") current_ammo = clip_size reloading = false print ("reload complete") func check_collision(): if raycast.is_colliding(): var collider = raycast.get_collider() if collider.is_in_group("Enemies"): collider.queue_free() print("Killed" + collider.name)
The class/inheritance solution to multiple weapons has totally revolutionised the way I design weapons in my game. Thank you so, so much for explaining how to define and inherit classes! I've even gone a step further and inherited from weapon to create three specialised classes: raycast_weapon, projectile_weapon and melee_weapon!
@@CodeWithTom It's working beautifully! It also makes it much easier to organise the weapons in my project, and to refer to them and use their stats in the game. This "template" approach is perfect for my game's modular weapon system. Thanks again for the idea! :D
Amazing tutorial, your content is simply great! I have been messing arroung with Godot and you have helped me a lot to work my way out. Thanks for the great videos!
The " is_colliding()" and "get_collider()" are not working i've been searching the web and can't find the replacement. Please let me know the solution.
For anyone wondering, at the time im at in the video you dont need the export infront of the var (var fire_rate etc.) it made my code not work so i wanted to put this out so you know the problem.
I dunno if he told this in future video and if anyone is still watching this video, but if you want to make a gun thats keeps shooting when the shoot button is pressed (or an *automatic gun*), change Input.is_action_just_pressed to Input.is_action_pressed in the func fire()
For those of you who want to reload when your ammo is at 0, simply put: if current_ammo < 1 and not reloading: reload() in the func _process(delta) function so you don't have to press r or shoot
Well here I am running into another problem. I'm at the point where we're coding the raycast to delete/kill enemies. I have everything set up as you put it. But nothing happens when I 'fire' on an enemy. It just prints 'fired weapon'. The enemy doesn't disappear. With 'Visible collision shapes' turned on I can see that the game knows something is there when I mouse over it. But wont do anything when I fire.
@26:16 I think the solution to directly access the label and change it every process frame is not a good practise in terms of both performance and single responsibility principle. The weapon class should not handle the UI elements. Instead what I think is that it should simply emit a signal and then the UI node should have a script that should capture that signal and then act upon it
wow, so appreciated. this is a great tutorial series. learning a lot, and excited to have a character that can already run around and kill enemies. thank you! got a question that I will try and research if I don't see it covered. Ill edit this comment when I find an answer... when my mouse is not in the screen area when starting, any click, clicks me out of the game again as if Id hit the escape key. is there a way to grab the mouse cursor, center it, then run the capture process? it's not an issue if I hit play and then get my mouse into the window area before it's fully loaded. oooh... you pulled a sneaky around 13:50 ... added the class_name without telling us. when we create shotgun.gd, gives a little error when trying to extend without the class_name in Weapon.gd ... dangit... should have just played another 5 seconds of the video... ;) alright, so I added the ready process that was put in shotgun.gd to the ready process in weapon.gd (so the shotgun can inherit the generic fire_range, and that can be brought into all future weapons as well). I feel like one change that I am going to work on as well is that the reload should be able to happen right after the last shot... at current, it is waiting for a timeout to allow another shot, and then that shot turns into a reload... really enjoying this. thanks again! What I would like to see next... (don't know if its in the playlist from where I am sitting now) is an inventory system, weapon selection, etc.... I like the idea of an FPS RPG, and I think that those two combinations for a game covers so many concepts and ideas of game design, that it could be a great teaching series in itself.
Please show us how to make enviromental hazards such as water or lava or fire or smoke or fog, scripts of things that appear and dissapear and physics of ropes! 🙏
everything works perfectly except the check_collision function, i shoot at the enemies but it doesn’t seem to detect it. do you know what would cause it?
Great tutorial I look forward to completing the whole series. I am having trouble with the function check_collision(): My Godot_v3.5.1 throws an error "Attempt to call function 'is_colliding' in base 'nul instance' on a null instance." Does anyone know to fix this. I have tried prefixing raycast with a $ sign without success. would like to move on cause the tutorials are great & easy to understand, big thanks to Tom for making the video's.
Remove the "just" is is_action_just_pressed. The "just" means it only checks the first time you click, and if you remove it then it will constantly fire every time the firerate timer is up as long as you're holding down the button.
Is it better to create a raycast in code or to create a raycasts object in the scene and just hiding/unhiding? I'm assuming in the scene because then you don't have to create and delete it every time, but it only works if it's always from the center of the camera to the middle of the screen
I don't get the if with the can_fire part, because it can't happend can_fire =true and current_ammo>0 at the same time. Unless you mean to use can_fire for another purpose like if sprinting=true or cutscene=true: can_fire=false and then it can't shoot
I need some help. The game was working fine until I added the exact same lines of code from line 33-38 at 17:35 and then every time I clicked to fire the weapon it brings up an error message saying “Attempt to call function ‘is_colliding’ in base ‘null instance’ on a null instance” as well as “get_node: Node not found: ../Head/Camera/Raycast.”
hello mister Tom i hope you are having a great day, I appreciate your tutorial. I need help with something though if I want to have no reload weapon can i just skip the steps of 8:00 - 12:00 min mark?
Is yield() a non blocking wait? What happens to other code in the same function during that time? Does it actually block further code execution but only for the _process() function which runs on every frame? What if I want to do other things in the _process() function in the mean time?
Good question. Yields are complicated to explain in a single response. But they are effectively a way of initiating coroutines, freezing the current state of execution and resuming once they receive a completed signal. You can read more here: docs.godotengine.org/en/3.0/getting_started/scripting/gdscript/gdscript_basics.html#coroutines-with-yield
17:55 ive checked that i wrote everything exactly as you wrote it countless times, yet upon firing, the game closes and says: "Attempt to call function 'is_colliding' in base 'null instance' on a null instance." can you help with this?
I know this is a kind of old video, but i did all the code right for this one i followed step by step but the raycast will not collide with anything? everytime i fire at one of the spheres it doesn't print or do anything. Halp
this is my code is anything wrong because when i go to fire i get an error extends Node class_name Weapon export var fire_rate = 0.5 export var clip_size = 5 export var reload_rate = 1 onready var raycast = $"../Head/Camera/RayCast" var current_ammo = clip_size var can_fire = true var reloading = false func _process(delta): if Input.is_action_just_pressed("primary_fire") and can_fire: # fire the weapon if current_ammo > 0 and not reloading: print("Fired weapon") can_fire = false current_ammo -= 1 check_collision() yield(get_tree().create_timer(fire_rate), "timeout") can_fire = true elif not reloading: print("Reloading") reloading = true yield(get_tree().create_timer(reload_rate), "timeout") current_ammo = clip_size reloading = false print("Reload complete") func check_collision(): if raycast.is_colliding(): var collider = raycast.get_collider() if collider.is_in_group("Enemies"): collider.queue_free() print("Killed " + collider.name)
i have to this error "Attemt to call function 'set_text' in base "null instanse" on a null instanse and this stroke error - raycast.cast_to = Vector3(0, 0, -fire_range)
Hi Joel, this approach uses Raycasts and not physical bullets. Imagine a raycast like a instant travel, invisible line, that detects if it hit something. In this case, the enemy. I will follow up with physical bullets in a future video.
Nice! I subbed in order to be guided by your brilliant ideas, as game development might be really difficult for a newbie! Btw.. i'm a linux developer and i want to upload my games for android platform later in the future but i have some problems with a program called adb.. Please if you can help me, then I would like from you to make a video on how to solve this kind of issue.. Thx for reading my comment!