Simple FPS Enemy AI in Godot - Make an FPS in Godot Part 4

  Рет қаралды 32,558

Code with Tom

Code with Tom

Күн бұрын

In this video I will show you how to create some Simple Enemy AI in Godot, complete with field of view and line of sight sensors.
Grab the code for the new scene setup to begin this tutorial here:
github.com/codewithtom/godot-...
Full Source Code for this tutorial can be found here:
github.com/codewithtom/godot-...
Support me on Patreon:
/ codewithtom
Join the discord:
/ discord
You can find the full Make an FPS in Godot series playlist here:
• FPS Character Controll...
This video covers creating a simple enemy AI system in our FPS game. We will use collision areas to create an enemy's field of view and raycasts to calculate line of sight which will allow our player to take cover behind objects. I'll also give you some handy tips for modifying the material of an object at runtime and implement a simple player chase script.
In this series of FPS Godot tutorials I will teach you how to make your very own FPS in Godot. Subscribe to stay up to date!
Music By: LAKEY INSPIRED @ / lakeyinspired

Пікірлер: 194
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Important note! In this video I use the _process function, but ideally you should use the _physics_process function instead due to RayCast calls and movement.
@_mickmccarthy
@_mickmccarthy 3 жыл бұрын
@tompo1975 Bit late, but if you haven't found an answer yet you can give reference a script as a class using 'class_name `, other scripts can then inherit from that by using `extends ` at the top, much like a regular script will have `extends Node` or similar at the top. Hope that helps!
@spyd_d1983
@spyd_d1983 3 жыл бұрын
I just did this but my enemy keeps walking away from me
@CodeWithTom
@CodeWithTom 3 жыл бұрын
@@spyd_d1983 hey, sounds like you need to rotate your enemy 180 degrees
@spyd_d1983
@spyd_d1983 3 жыл бұрын
@@CodeWithTom no that doesn’t work it just goes backwards in the same direction no matter where I put it and when I rotate it it just goes forward in the same direction
@CookieMagician
@CookieMagician 4 жыл бұрын
bruh literally watched the first three episodes yesterday and was sad there was no episode 4. Thanks!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thanks for watching, hope you enjoyed part 4 😁
@MrAndrjuha
@MrAndrjuha 4 жыл бұрын
@@CodeWithTom We will enjoy if these episodes continues:-)
@seannesler
@seannesler 4 жыл бұрын
Thank you! This helped so much! I am trying to get back into game design after years, totally new to Godot, and this helped a LOT. Just a couple bugs I am sure there are easy fixes for that I just can't figure out. 1) I added two AIs to a scene and both turn red when one sees the player character. 2) If the player character is standing on an elevated surface, the AI will turn until it is practically horizontal to look at the player. The AI used to literally fly to reach the player if the player was elevated, but I fixed that easily (watched the gravity tutorial you made and that kept them from flying).
@jowilson5581
@jowilson5581 4 жыл бұрын
This is fantastic. With these four videos, I have a nice framework in place to make my own game idea! Thanks so much for the leg up.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
You're very welcome Jo. I'm planning to refine these lessons and extend them into a full fledged course at some point. I'm also toying with the idea of releasing an open source first person framework
@jowilson5581
@jowilson5581 4 жыл бұрын
@@CodeWithTom fwiw I think releasing the core functionality as a plug-in framework would be a nice gesture, very much in the spirit of Godot. I'm actually making some changes to what we've done so far, as the game I have in mind is a stealth game where the player has a slingshot as opposed to a hitscan weapon. But! Just having core stuff like movement keys, mouse look, interactable objects, and a basic raycast in place demonstrating layers and groups, it all makes for a nice base on which to build.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
@@jowilson5581 absolutely! The Ludum Dare entry I made uses projectile bullets instead of hitscan so id probably add that in too. Although it's a little buggy right now which I believe is to do with the speed of the bullet and the rate at which the collision area node reports bodies entering it. Will need to figure out the issue first. Also thinking of adding in things like customizable head bobbing, sway, camera shakes etc.
@AceSpectre
@AceSpectre 4 жыл бұрын
Thanks for continuing this series, i was using it to guide me through 3d in Godot and noticed that it cut off at part 3. Youve definitely made my quarantine project easier!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Glad to hear it! :D
@abdulbasitado6180
@abdulbasitado6180 4 жыл бұрын
It's good to have you back Tom. I was basically heartbroken when the videos stopped coming.. Thank you.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thanks it's great to be back! 😁
@vickylance
@vickylance 4 жыл бұрын
I really hope that you continue these tutorials you have got a knack to make these tutorials really enjoyable
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you Vignesh, there are plenty more to come.
@larsthedude1984
@larsthedude1984 Жыл бұрын
This is EXACTLY what I needed for my stealth game. Thank you!!
@tridra5714
@tridra5714 4 жыл бұрын
Been waiting for this. So glad its finally here
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Glad you're here to watch it! :)
@sandakureva
@sandakureva 2 жыл бұрын
I originally found your channel because I was stuck on a specific problem for a specific game jam... but I've decided to stick around because all of the content is pretty good.
@mikebrolo
@mikebrolo 4 жыл бұрын
Been waiting for a while!!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Apologies for the wait! haha
@ashkantofangdar6591
@ashkantofangdar6591 4 жыл бұрын
Fantastic i am surprised that these videos have so much low like, but keep up the good work. from the last three episodes i can even create my idea that i had struggled with in past 5 month.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
That's amazing Ashkan, happy I could help!
@ratrodshaggy4840
@ratrodshaggy4840 4 жыл бұрын
Absolutely awesome tutorials. It’s perfect for someone with attention span issues. Fast, efficient and to the point. I’ve watched other tutorial videos that give the same amount of instruction, but the video is over an hour long because they keep going off on tangents. Drives me nuts. Anyway, I’ve subscribed and can’t wait for more videos. Are you gonna do any about how to do build a scene with textures and objects. I have no idea how all that works. Thanks again.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you so much for the kind words Ratrod. Glad you find these tutorials useful and concise 😁
@frankoesavage8314
@frankoesavage8314 4 жыл бұрын
Yeah hes right, I can listen and know whats going on while not even watching the video, Voice is perfect. I like how he isnt overly funny neither, but if you pay attention closely there some funny jokes in there somewhere lol
@explosivesexplode
@explosivesexplode 3 жыл бұрын
If you're having issues with "Invalid get index 'collider' (on base: 'Dictionary'). Add if not result.empty(): before if result.collider.is_in_group("player"): My code looks like this: if target: var result = space_state.intersect_ray(global_transform.origin, target.global_transform.origin) if not result.empty(): if result["collider"].is_in_group("Player"): Thanks to the people in the Godot discord for helping me out.
@chrislenz
@chrislenz 2 жыл бұрын
Thanks! This is exactly what I was having issues with.
@rachidazekaoui4306
@rachidazekaoui4306 Жыл бұрын
Wow thanks!
@frankoesavage8314
@frankoesavage8314 4 жыл бұрын
very exciting videos, Brings me back to the learning days of Unity3d for sure! Bringing back the best, thank you
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you Frankoe I really appreciate it :)
@ryoneer
@ryoneer 3 жыл бұрын
FOR ANYONE WITH THE GET INDEX COLLIDER ERROR!!!: Check and see where the origin of the player and the enemy nodes are. In my case they were at y= 0 and the floor level was also at y=0 which means the raycast is in the floor, thus cant reach the player, if anything for that matter. I fixed it by placing a spatial node on both the player and on the enemy at about half the body height and raycasting from there.
@AsimFojiOfficial
@AsimFojiOfficial Жыл бұрын
wait can u explain. I dont understand. I am getting this error though
@Bananeisafree
@Bananeisafree 4 жыл бұрын
Pretty darn good tutorial series !
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Glad you like them! Thank you!
@smutnywalen
@smutnywalen 4 жыл бұрын
Nice and simple video. Good work!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you! Cheers!
@masterox2
@masterox2 4 жыл бұрын
I really like your tutorials
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you Shadow! 😁
@amirghalbarband3038
@amirghalbarband3038 2 жыл бұрын
Thank you so much man, your tutorial is really helpful
@pascalcasier959
@pascalcasier959 4 жыл бұрын
Thank you for another great tutorial.
@spooky130u
@spooky130u 4 жыл бұрын
I love the way you do the tutorials---describing everything in detail as you add it, and then doing a full recap at the end. Fantastic....makes it much easier for someone who, during his first cancer, had 3 brain tumors, three very severe brain surgeries, whole-brain/max-dose radiation therapy, plus very severe chemo which does cross the barrier into the brain, to learn from. Btw, minor point: are there supposed to be two part 4s? :-)
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hi Jim, thank you so much for the feedback. I'm really glad you find my method of teaching useful. It sounds like you've gone through an awful lot, but it fills me with joy to hear that my videos are helping you to learn game development and I wish you every success in your journey! 😁👍
@spooky130u
@spooky130u 4 жыл бұрын
Is there supposed to be a part 5? The title and video for four and five are the same. Just wondering. Don't want to miss the end of this tutorial set! :-) In part four (the actual part four not part four that's #5), you mention that the new setting is for something you'll be adding later. I gather, since it really wasn't used in part four, that there is a missing part five. But I could be mistaken. Oh, and the zip with the code is also labelled part 4. As for going through a lot, yes, definitely. But I put cancer #1 through hell. Every time it tried to kill me, the only thing it accomplished was to make me more furious with it and that much more defiant towards it. We caught cancer #2 so early it was just one surgery and done. And we caught #3 before it even became #3 (pre-cancerous mass). My email signatures read: The score: Me: 2 + 1-ish Cancer: 0The really bad thing is that #1 forcibly retired me and dumped me into Social So-Called Security Disability. Gamedev is my latest attempt at (eventually) making enough money to escape from this financial hell.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hey Jim, good spot! There are only 4 parts, looks like I mistakenly added part 4 to the playlist twice. Part 5 will be coming soon 😁
@spooky130u
@spooky130u 4 жыл бұрын
@@CodeWithTom Looking forward to it.
@infelicitas
@infelicitas 4 жыл бұрын
Awesome! thanks man
@CodeWithTom
@CodeWithTom 4 жыл бұрын
You're very welcome :)
@juiceman7649
@juiceman7649 3 жыл бұрын
Was about to subscribe until I realised it's Code with Tom no surprises there best Godot tutorials on youtube, making my beginner coding journey possible.
@kingzeeb319
@kingzeeb319 4 жыл бұрын
Awesome series, thanks a lot! I'm trying to apply this to a Doom Clone, it's all good except there aren't many tutorials on Doom-like billboards with directional sprites in a 3D environment.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Interesting idea, I'll add it to my list of topics 😁
@strum007
@strum007 4 жыл бұрын
Miziziziz has a video on that
@shire7949
@shire7949 4 жыл бұрын
Cool as always! thanks.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you too!
@AleksandarPopovic
@AleksandarPopovic 4 жыл бұрын
Good jobe, and good luck with, your projects!!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Cheers Aleksander
@Nyterian
@Nyterian 4 жыл бұрын
Please continoue this series
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Absolutely 😁👌
@truthtoons8833
@truthtoons8833 Жыл бұрын
Thank you!
@joyeldsilva
@joyeldsilva 2 жыл бұрын
Can you do a tutorial on enemy shooting bullets?
@justinwaluigi5485
@justinwaluigi5485 3 жыл бұрын
The enemy targeting the player doesn't work. Seems like look_at might be changed or removed from this version.
@giantenemycrab5596
@giantenemycrab5596 Жыл бұрын
Does the enemy have a problem where it points at the player but there orientation is wrong (e.g face down) and it won't track the player? I might have a fix, otherwise, no idea
@thegamebums6791
@thegamebums6791 4 жыл бұрын
can the next episode be another episode on the enemy AI system? The one that I am currently using isn't working for the game I'm busy making. I am just asking if it can be in the next episode, thanks. Great tutorials btw!
@panskibinski
@panskibinski 3 жыл бұрын
The issue with enemy clones turning red/green together is that they share the same spatial material instance. The solution is to create new one for each of them at the creation or update
@andi8489
@andi8489 4 жыл бұрын
Thank you very much! Your tutorials are the best. I try to make a simple fps engine with some modern features like camera shake when shooting or blood overlays splat to walls when enemies are hit. Could you include something like that? A sprite weapon and sprite enemy would be nice too. I aim to have 4 directional sprite enemies. Aaand are trigger areas possible? Lets say the player walks into an area, the light goes out and a sound plays.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Great suggestions, I'll definitely add them to my list of topics to cover!
@monkeyballs188
@monkeyballs188 4 жыл бұрын
instead of passing different functions for the color changing, you can make one function and pass arguments for the colors instead
@tiinaposkiparta9880
@tiinaposkiparta9880 4 жыл бұрын
Amazing and interesting!!! 🙋😁
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thanks Tiina 😁
@tiinaposkiparta9880
@tiinaposkiparta9880 4 жыл бұрын
@@CodeWithTom You're very welcome 😁
@fragarena9910
@fragarena9910 4 жыл бұрын
love your tuts
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thank you 😊
@fragarena9910
@fragarena9910 4 жыл бұрын
@@CodeWithTom yeah , it's been quite a while since your last fps tut 😄
@aetheriet9363
@aetheriet9363 3 жыл бұрын
Don't expect you to respond but could you do a video on adding gravity and jumping to the enemies AI
@PabloMartinez-qf4yr
@PabloMartinez-qf4yr 4 жыл бұрын
Awesome!
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Thanks Pablo!
@RobiworksLt
@RobiworksLt Жыл бұрын
Thank you,
@grassly7997
@grassly7997 3 жыл бұрын
im having a problem at 13:25, for some reason when the enemy sees me they turn the opposite way of me. Every time i go into their FOV they just turn by 180°
@LeKooKoo
@LeKooKoo 3 жыл бұрын
I had the same issue but I fixed it by rotating the Enemies Area the other way.
@Allen-cx6yi
@Allen-cx6yi 3 жыл бұрын
I have the same problem I tried rotating the area and nothing happened pls help
@mahyuddinchan3012
@mahyuddinchan3012 2 жыл бұрын
@@Allen-cx6yi I changed the collisionPolygon node to -90 degrees in transform and changed the area node to 90 degrees in trasform. hopes this helps!
@naraz927
@naraz927 2 жыл бұрын
@@mahyuddinchan3012 thanks it helped a lot!
@lionlight9514
@lionlight9514 2 жыл бұрын
@@mahyuddinchan3012 Wait on which axis was the x y or z?
@cosmicfruit7111
@cosmicfruit7111 2 жыл бұрын
How would you apply gravity to the enemy?
@larrybird3729
@larrybird3729 4 жыл бұрын
btw how would you make the enemy look at the target slower? instead of instant? Thanks
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hi Larry, you would need to use linear interpolation. I will do a video on this topic in the future.
@bulaxa2900
@bulaxa2900 4 жыл бұрын
Instead of making groups you could just use the collision layers inside of the engine in the inspector, in the game i'm currently working on instead of using the groups i used layers, and it's quite the same thing but I prefer the layers method
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Yep that's another option too 😁
@jlewwis1995
@jlewwis1995 4 жыл бұрын
It seems like it would be better to create a more cone shaped trapezoid for the viewing area rather than a completely flat one, can you do that with the collision polygon?
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hey James, very good point. The CollisionPolygon, from what I can tell, has a set height. You may want to opt for a CollisionShape to do something more like a cone. Or simply use a Sphere and check the angle to the player to see if it falls within your desired FoV. But good point! :)
@tubagusthariqgilbraltar7499
@tubagusthariqgilbraltar7499 4 жыл бұрын
What is state machine use for???
@efimov90
@efimov90 4 жыл бұрын
Enemy feels like dalek. It was really scary after i add tracking code. It was fun.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Glad you enjoyed it :)
@atharvvbhandare
@atharvvbhandare 3 жыл бұрын
Thanks sir plz make a video to add sound effects and particles
@blacksaturdayrecords3212
@blacksaturdayrecords3212 3 жыл бұрын
when i make rooms and i look past a certain distance, the background clips with the WorldEnvironment node. How do I fix this?
@jlewwis1995
@jlewwis1995 4 жыл бұрын
How computationally expensive is directspacestate? Wouldn't it be more optimized to have a raycast node that only gets enabled when a non-world object enters the viewing area? I could see grabbing the whole world stare getting *really* bad in terms of cpu and ram use if you have a large map with lots of enemies
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Good question. I've not ran any benchmarks but I believe it is extremely cheap to run raycasts in this way. Especially since we only grab a reference to the space state object once (during the _ready call). It's main purpose is to make physics queries like we're doing here. docs.godotengine.org/en/3.2/classes/class_physicsdirectspacestate.html
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Note, you may want to modify the code slightly to call this inside the _physics_process instead for thread safety.
@joshuapasco9026
@joshuapasco9026 3 жыл бұрын
I'm not sure why.. But when I enter the Area, it prints myself as "Player entered" just fine, but when I put if body.is_in_group("Player"): it doesn't detect or print anymore. Have I somehow changed my group? But exiting still prints, just not entering. Thank you. func _on_Sight_body_entered(body): if body.is_in_group(Player): print(body.name+" entered") func _on_Sight_body_exited(body): print(body.name+" exited")
@mldsh
@mldsh 4 жыл бұрын
Hello Tom! Can you help me with my problem please? Debugger: "Invalid get index 'collider' (on base: 'Dictionary'). It's happening when I exiting Area. I don't know what to do
@vickylance
@vickylance 4 жыл бұрын
Rewatch the tutorial and see carefully see which part you missed.
@_mickmccarthy
@_mickmccarthy 3 жыл бұрын
To those having the "Invalid get index 'collider' (on base: 'Dictionary')" error, it does (to me at least) seem to be an OSX-specific issue. Unfortunately this isn't the first time I've had OSX-specific issues with Godot. I'm now running the project on Linux and of course Tom (and many others I assume) are running it on Windows with no issues.
@lukepire
@lukepire Жыл бұрын
Whn i play my game the enemy just goes to 0,0,0 and when i wal in fron of the enemy it doesnt pick up in the output box
@The10ie
@The10ie 3 жыл бұрын
how did you get the crosshair
@abbaszangaraky5693
@abbaszangaraky5693 3 жыл бұрын
Hi Can I use this tutorial in my project? Not problem?
@kushagrajain5681
@kushagrajain5681 2 жыл бұрын
i always got "Invalid get index 'collider' (on base: 'Dictionary')" error when in i jump in enemy radar
@gdmattartz3071
@gdmattartz3071 4 жыл бұрын
sometimes im having an error called Invalid get index 'collider' (on base: 'Dictionary'). how can i fix this?
@ryoneer
@ryoneer 3 жыл бұрын
found a fix yet?
@ryoneer
@ryoneer 3 жыл бұрын
found a fix. look at recent comment from me its the origins of enemy and player messing up the raycast
@ohmyshell
@ohmyshell 4 жыл бұрын
where are the object shadows? it looks so flat. Cant wait for the rest of the series. Hope you cover post processing and graphics.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Heh, yes I'll cover this in a future tutorial
@ouhellouder9269
@ouhellouder9269 2 жыл бұрын
i actualy followed this tutorial and in part when enemy doesnt see us behind the wall dont work every time i go away from wall he can see me and chase me
@bronxzoo8344
@bronxzoo8344 2 жыл бұрын
I AM JUST GETTING STARTED IN THIS, SO I LOOK FOR HELP , AND IN THIS VIDEO, THE ONLY THING THAT IS WORKING FOR ME IS THE COLOR AND THE PART THE ENEMY IS LOOKING AT ME, NOTHING ELSE WORKS. ANY ANSWERS / TOM.
@BogdanKustan
@BogdanKustan 4 жыл бұрын
Nice content, only some comments: 1. Why not use _physics_process instead of _process? All physics stuff must be handled in _physics_process(): move_and_slide -- This method should be used in Node._physics_process (or in a method called by Node._physics_process), as it uses the physics step’s delta value automatically in calculations. Otherwise, the simulation will run at an incorrect speed. 2. move_and_slide() doesn't need multiplication by delta: move_and_slide -- Unlike in move_and_collide, you should not multiply it by delta - the physics engine handles applying the velocity. 3. Why not to give each entity a class_name and then check it using "colider is Player" instead of using groups?
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hey Bogdan, you're absolutely right! It's been a few months since I've touched Godot and I'm a little rusty as you can tell 😂 All of your points are 100% valid and I appreciate you pointing them out. I like your type checking solution rather than checking the groups too! Thanks for the constructive comments. 😁👌
@liemaeu
@liemaeu 4 жыл бұрын
I get the error: invalid get index 'collider' (on base: Dictionary) at the line if result.collider.is_in_group("Player"):
@_mickmccarthy
@_mickmccarthy 3 жыл бұрын
@deadninja Did this work for you? As collider isn't a function, so I can't see how it would. I added a check for the presence of a collider property and it seems that the result does not have one. Also added a breakpoint and inspected it and there is no collider property.
@_mickmccarthy
@_mickmccarthy 3 жыл бұрын
@deadninja Odd! What version of Godot are you running if you don't mind me asking? Might be a small difference between versions or something. There seems to be both a lot of people where this tutorial works fine and a lot who are having this particular issue. Very strange!
@_mickmccarthy
@_mickmccarthy 3 жыл бұрын
@deadninja Looks like it's an OSX problem, started the tutorial on OSX. Moved across to Linux once I couldn't find a simple solution and everything worked fine. Pulled the changes back to OSX to verify it was OSX and it crashed again when spotted by an enemy.
@ishkapoor7931
@ishkapoor7931 4 жыл бұрын
totally loved your tutorial... part-4 is really amazing... but I ran into a problem... kindly help!!! in the enemy script|func _on_Area_body_entered(body)|.... there is an error that popped up "Attempt to call function 'Albedo_color' in base 'null instance' on a null instance". please help! I want my game to work properly... the game crashes whenever I come across the enemy.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hey Ish, thank you! Looks like you're trying to call a function called "Albedo_color". It should be "set_albedo". Give that a go and let me know if that fixes it. Also feel free to join the discord if you need further assistance 😁
@ishkapoor7931
@ishkapoor7931 4 жыл бұрын
@@CodeWithTom well I used |func set_color_red(): $MeshInstance.get_surface_material(0).set_albedo(Color(1,0,0)) | as the function and |set_color_red()| to call the function.... but every time I run this... |Attempt to call function 'set_albedo' in base 'null instance' on a nullinstance.|
@thedevine3756
@thedevine3756 4 жыл бұрын
Is it possible to add building mechanics?
@CodeWithTom
@CodeWithTom 4 жыл бұрын
I was actually just thinking about this... So possibly in the future 😁
@BirdaoGwraBasumatary
@BirdaoGwraBasumatary 3 жыл бұрын
Please make how to change weapon.
@ThatGatorGuyTGG
@ThatGatorGuyTGG 2 жыл бұрын
Hello, for those whom are having the albedo problem "attempted to call function 'albedo_color' in base 'null instance'" when running the get_surface_material. The only solution around it with the same architecture of code is to use get_active_material instead. At least for Godot version 3.4.4. My 'guess' to why get_surface_material doesn't work is that it only returns the material for the surface of the mesh and that material is something different than the material used for drawing the mesh? Godot says that it is null which means it hasn't been assigned anything. When using get_active_material it returns the correct material. This is just my ignorant guess lol. No idea why it works for some and doesn't for others? If it helps I am on Linux, Arch 5.18.3, LLVM 13.0.1, and Godot 3.4.4.
@mackenzienewton4829
@mackenzienewton4829 Жыл бұрын
thank you so much i pulling my hair out on this one😅
@mrmixedvideomaker9767
@mrmixedvideomaker9767 4 жыл бұрын
Nice video, but when I entered the enemy's field of view, it turns away, making it green. please help.
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Sounds like you may need to rotate your enemy mesh by 180 degrees on the Y axis.
@thilosaur2169
@thilosaur2169 3 жыл бұрын
Had the same problem, fixed now
@Icie145
@Icie145 3 жыл бұрын
so instead of the enemy looking at me, he looks in opposite direction, I follow the same code as you did edit: The rotation works, but how do i lock the y rotation?
@spyd_d1983
@spyd_d1983 3 жыл бұрын
Mine did the same thing and all I was move the nose to the other side and rotate the area by 180 degrees
@plurakok
@plurakok 3 жыл бұрын
Same problem here
@yurimednikov304
@yurimednikov304 3 жыл бұрын
@@spyd_d1983 That worked for me! Thanks!
@sabinekine2737
@sabinekine2737 3 жыл бұрын
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@FarmMyCrops
@FarmMyCrops 3 жыл бұрын
@@sabinekine2737 worked for me thanks so much
@Shortclipsyt9
@Shortclipsyt9 4 жыл бұрын
pls part 5 of make an FPS Game :)
@CodeWithTom
@CodeWithTom 4 жыл бұрын
I will, but it might be a while. I have a lot of things I'd love to cover :) I'm actually considering re-doing the series as a full course.
@thilosaur2169
@thilosaur2169 3 жыл бұрын
My enemy runs away instead of coming towards me. How can i fix this?
@sabinekine2737
@sabinekine2737 3 жыл бұрын
Try this: King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@Shortclipsyt9
@Shortclipsyt9 4 жыл бұрын
how can i make that the enemy kills me / attack
@CodeWithTom
@CodeWithTom 4 жыл бұрын
I have it on my list of topics to cover :)
@Shortclipsyt9
@Shortclipsyt9 4 жыл бұрын
@@CodeWithTom that would be amazing :)
@Shortclipsyt9
@Shortclipsyt9 4 жыл бұрын
@@CodeWithTom and another question, is there any way to make win the game after collecting for example 5 coins or something ? :)
@unworthy.potato
@unworthy.potato 3 жыл бұрын
11:44
@ya_boi_logs9792
@ya_boi_logs9792 3 жыл бұрын
Hey, I just finished coding the part of the tutorial which is debugged at 13:48 and I can't seem to get it working. Before I started this step it was working fine (The change color when in line of sight part). But now when I add in the 'following the player' step, the enemy just sits there and doesn't move, change colors, or anything else. There also isn't an error popping up in the engine after I have tried the debug. Thanks for the help!
@jenilamansalapus8636
@jenilamansalapus8636 3 жыл бұрын
did you add the player to group?
@supremeasura3358
@supremeasura3358 3 жыл бұрын
these capsules looking hella sus ngl
@pravinvjreigns6055
@pravinvjreigns6055 Жыл бұрын
My enemy looks opposite to the player,please put video about it
@simplesten3450
@simplesten3450 Жыл бұрын
Had the same issue. I fixed it because the AI was built “backwards” try moving the face to the other side of the AI. Hope that helps!
@pedroluzio
@pedroluzio Жыл бұрын
For some weird reason my Enemy is upset with my Player... everytime I enter his field of view he turns 180 degrees the oposite side :( lol
@invaderHUNK
@invaderHUNK Жыл бұрын
Have you tried apologizing?
@jamesxxxyz8775
@jamesxxxyz8775 4 жыл бұрын
Enemy look too fast to the player. How can you do this smooth? 13:48
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Valid point, this was mostly for demonstration purposes. But you can achieve this by using linear interpolation between the enemy's current direction and the direction to the player. I will cover this in another tutorial in the future.
@BogdanKustan
@BogdanKustan 4 жыл бұрын
I am doing something like this in _process(): var needed_angle = get_angle_to(player.global_position) rotation = lerp_angle(rotation, needed_angle, delta)
@CodeWithTom
@CodeWithTom 4 жыл бұрын
@@BogdanKustan Great solution 😁
@davidheadley8589
@davidheadley8589 3 жыл бұрын
@@BogdanKustan it says get_angle_to isn’t declared in current class. I’m sure I’m just messing up somehow
@cringedmossy5260
@cringedmossy5260 4 жыл бұрын
hi :emojy:smile
@magma0473
@magma0473 4 жыл бұрын
Enemy looks away for some odd reason? Please help
@nightRobinO_O
@nightRobinO_O 4 жыл бұрын
In Godot 3D, the front is the negative Z axis. Rotate your enemy first to face the -Z axis
@sabinekine2737
@sabinekine2737 3 жыл бұрын
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@bigbird612
@bigbird612 4 жыл бұрын
where is the github link?
@CodeWithTom
@CodeWithTom 4 жыл бұрын
Hi Nucleas, it's in the description.
@bigbird612
@bigbird612 4 жыл бұрын
@@CodeWithTom thanks for some reason it wasnt showing me them
@bobojenkins5805
@bobojenkins5805 2 ай бұрын
12:04 is what you clicked for
@bobojenkins5805
@bobojenkins5805 2 ай бұрын
nobody has enough balls to code a logic for projectile enemies. you made a capsule follow the player thats cool i guess
@hshsjsjsj506
@hshsjsjsj506 4 жыл бұрын
look_at(target.global_transform.origin, Vector3.UP) at this line why my enemy is looking in opposite direction its not following my player . please help me hahah
@nightRobinO_O
@nightRobinO_O 4 жыл бұрын
In Godot 3D, the front is the negative Z axis. Rotate your enemy first to face the -Z axis
@tr3xmusic852
@tr3xmusic852 3 жыл бұрын
Bruh my enemy looks away when Im in front of him, help
@immanuelc885
@immanuelc885 3 жыл бұрын
same
@hrithikjoshi6918
@hrithikjoshi6918 3 жыл бұрын
same, did you find a fix?
@sabinekine2737
@sabinekine2737 3 жыл бұрын
King Dunnad 8 months ago This happens because your enemy turns the wrong way, and then the player is out of the enemy's line of sight. To fix this: (You don't have to set the translation to be exactly the same as I have, roughly the same should work) Go to Enemy scene. Click on the MeshInstance node (the capsule). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: -180, z: 0. Scale is fine as it is. Click on the MeshInstance2 node (the cube to point where it's going). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0.7, z: -0.8. Set Rotation Degrees to x: 0 y: 0, z: 0. Scale is fine as it is. Click on the CollisionShape node (to collide with the enemy). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Scale should be all 1. Click on the Area node (the field of view). Go to the Inspector tab and click to expand Transform. Set Translation to x: 0, y: 0, z: -1.063. Set Rotation Degrees to x: 0, y: 90, z: 0. Scale should be all 1. Click on the CollisionPolygon node (the field of view collision area). Go to the Inspector tab and click to expand Transform. Translation should be all 0. Set Rotation Degrees to x: 90, y: 0, z: 0. Hopefully that helps.
@youzzaim4010
@youzzaim4010 2 жыл бұрын
anybody elses enemy going to 0, 0, 0 instead of the play @Code with Tom. pls help
@VahitCanEmen
@VahitCanEmen Жыл бұрын
I wrote the code, but she avoids me as if she is offended by my character.
@ranjunewar3776
@ranjunewar3776 3 жыл бұрын
Tom pls Upload All Videos Fastly We can't waif for 1 week man
@arkhangelgeos120
@arkhangelgeos120 Жыл бұрын
i understand that it is old tutorial but if anyone can help me, problem "Invalid call to func "intersect_ray" in base 'GodotPhysicsDirectSpaceState3d', here the code at whitch i stuck: extends CharacterBody3D var _space_state var target func _ready(): _space_state = get_world_3d().direct_space_state func _physics_process(delta): if target: var result = _space_state.intersect_ray(global_transform.origin, target.global_transform.origin) if result.collider.is_in_group("Player"): look_at(target.global_transform.origin, Vector3.UP) set_color_red() else: set_color_green() func _on_area_3d_body_entered(body): if body.is_in_group("Player"): target = body print(body.name + "entered") set_color_red() func _on_area_3d_body_exited(body): if body.is_in_group("Player"): target = null print(body.name + "exited") set_color_green() func set_color_red(): $MeshInstance3D.get_active_material(0).set_albedo(Color(1, 0, 0)) func set_color_green(): $MeshInstance3D.get_active_material(0).set_albedo(Color(0, 1, 0))
Weapon Camera & Aim Down Sights - Make an FPS in Godot Part 5
23:49
Code with Tom
Рет қаралды 25 М.
The Jolt Physics Engine
11:23
Gamefromscratch
Рет қаралды 34 М.
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 32 МЛН
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 31 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 122 МЛН
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 490 М.
Finite State Machines in Godot 4 in Under 10 Minutes
7:16
Bitlytic
Рет қаралды 251 М.
Enemy AI Series 1: The State Machine
12:10
Garbaj
Рет қаралды 50 М.
How I designed Fruit Ninja
22:58
Luke Muscat
Рет қаралды 6 МЛН
Light Detection in Godot 4.0
6:24
GameDev Compass
Рет қаралды 8 М.
How To Make A Doom Clone In Godot 4
27:57
MizizizizTutorials
Рет қаралды 69 М.
Exporting Characters and Animations From Mixamo To Godot 4!
11:50
FinePointCGI
Рет қаралды 26 М.
You're not using Godot to its potential
6:12
Tienne_k
Рет қаралды 83 М.
The Future of Game Development
8:58
Brackeys
Рет қаралды 1,2 МЛН