How to Talk to NPCs! (or Interact with any Object, Open Doors, Push Buttons, Unity Tutorial)
168K views ยท Oct 12, 2022 ยท Education
Comments ยท 285
@CodeMonkeyUnity ยท 4 years ago ยท pinned
โ Get the Project files <a href="https://unitycodemonkey.com/video.php?v=LdoImzaY6M4">https://unitycodemonkey.com/video.php?v=LdoImzaY6M4 </a><br>๐ Get my Complete Courses! โ <a href="https://unitycodemonkey.com/courses">https://unitycodemonkey.com/courses </a><br>๐ Learn to make awesome games step-by-step from start to finish. <br>๐ Click on Show More <br>๐ฎ Get my Steam Games <a href="https://unitycodemonkey.com/gamebundle">https://unitycodemonkey.com/gamebundle </a><br> <br>POLYGON - City Pack <a href="https://cmonkey.co/synty_city_talknpcs">https://cmonkey.co/synty_city_talknpcs </a><br>POLYGON - Heist Pack <a href="https://cmonkey.co/synty_heist_talknpcs">https://cmonkey.co/synty_heist_talknpcs </a><br>Basic Motions Animations <a href="https://assetstore.unity.com/packages/3d/animations/basic-motions-157744?aid=1101l96nj&pubref=talktonpcs">https://assetstore.unity.com/packages/3d/animations/basic-motions-157744?aid=1101l96nj&pubref=talktonpcs </a><br> <br>๐ด RELATED VIDEOS ๐ด <br>Why you should NOT make everything PUBLIC! <a href="https://www.youtube.com/watch?v=pD27YuJG3L8">https://www.youtube.com/watch?v=pD27YuJG3L8 </a><br>Simple Chat Bubble in Unity! (Chat, NPC, Multiplayer) <a href="https://www.youtube.com/watch?v=K13WnNL1OYM">https://www.youtube.com/watch?v=K13WnNL1OYM </a><br>Kickstart your game with First and Third Person Controllers! (FREE Unity Starter Assets) <a href="https://www.youtube.com/watch?v=jXz5b_9z0Bc">https://www.youtube.com/watch?v=jXz5b_9z0Bc </a><br>Make your Animations DYNAMIC with Animation Rigging! <a href="https://www.youtube.com/watch?v=LEwYmFT3xDk">https://www.youtube.com/watch?v=LEwYmFT3xDk </a><br>SMOOTH with LERP! (Move, Rotate, Float) <a href="https://www.youtube.com/watch?v=jAN2IoWdPzM">https://www.youtube.com/watch?v=jAN2IoWdPzM </a><br>What are Interfaces? (C# Basics) <a href="https://www.youtube.com/watch?v=MZOrGXk4XFI">https://www.youtube.com/watch?v=MZOrGXk4XFI</a>
9
@GiraPrimal ยท 4 years ago
<a href="https://www.youtube.com/watch?v=LdoImzaY6M4&t=955">15:55</a> Optimization tip for the distance checking part:<br>- Vector3.Distance involves a square root in the math, which is super slow to compute. Since you're only checking which object is the closest, you can use squared distances to remove the square root and make the check faster.<br>- There's no Vector3.SquaredDistance static method, however you can use (pos1 - pos2).sqrMagnitude. This returns the squared distance between pos1 and pos2.
132
@petersaup ยท 4 years ago
I really must be getting better at this coding thing because the whole video I was like, "This code is neither nice or clean, why isn't he using an interface!" You got me good CM! Cheers!
28
@hypercharge26 ยท 4 years ago
Exactly when I am stuck on a point, code monkey comes from heaven to save me. Thank you so much CM!!
44
@Slumbjorn ยท 4 years ago
ahem......... <b>*GENERAL KENOBI*</b>
9
@kevinmatthews6369 ยท 4 years ago
Fantastic teaching. I've watched enough of your videos to anticipate we'd get to interfaces, but buildup (showing the scaling issues and the solution) is a fantastic teaching method.
10
@Spridonculous ยท 4 years ago
Oh man, I was stumbling my way through basically this very thing, but started with object interaction and was going to use it as the base for my NPC conversations. But then you come along and show off the right way to do it. Thanks! Now I get to go fix everything I did wrong.
9
@fcf8269 ยท 1 year ago
For simple games it is OK to just store massive amounts of NPCs and game objects; but for more performant games that have large amount of entities, you may want to use the notification event system. In that way when you are close enough to an NPC is the NPC itself to trigger the event "canInteract" for example, and your UI display the E key action. <br><br>This saves you to have to parse EVERY game object in that layer; which is one of the slowest operations in general, but in particular in Unity.
1
@ewwitsantonio ยท 4 years ago
Excellent video! Covered some great topics, demonstrated them in a clear and thorough manner, and the visuals and initial setup of the project are beyond the normal tutorial grade. Great work :)
9
@mehow. ยท 4 years ago
I got really scared after seeing the solution without an interface, thinking that this would be your final proposal :) great tutorial!
1
@KushagraPratap ยท 4 years ago
Quality of your video has improved a lot since I last visited sometime ago. Keep it up:)
1
@kunj1064 ยท 4 years ago
After a long time I came to see video I was busy . I was studying web development. Again awesome video .
1
Up next

How to Pick up and Drop Objects/Items! (First and Third Person, Unity Tutorial)
Code Monkey ยท 115K views

What are Interfaces? (C# Basics)
Code Monkey ยท 250K views

This Impossible Wave Puzzled Scientists for Centuries
Veritasium ยท 950K views

How to make a HEALTH BAR in Unity!
Brackeys ยท 1.3M views

Unity 6.3 LTS Beginner Tutorial #15 | Timed Challenges & Win/Loss
Crazy Carrot Studios ยท 17 views

Chess, But My Pieces Are AREA 51 ALIENS...
Chesslitics ยท 1M views

How to Climb Ladders (First Person, Third Person, Unity Tutorial)
Code Monkey ยท 46K views

Unreal Engine Developer Tries Scratch for the First Time
Its Rascal ยท 140K views

I Forced the World's Smartest AIs to Cooperate In a Game I Built... (It Got Ugly)
Kept You Waiting ยท 394K views

The Janitor made Him HUMBLE | Anatoly Gym Prank
ANATOLY ยท 331K views

Can I Make a Better AI Than AI?
commonLuke ยท 1.3M views

Your First Game in Unity: Ghost Evader: Part 11: UI Manager
Kelvar's Game Development ยท 114 views

How to Craft Items with Scriptable Objects! (Unity Tutorial)
Code Monkey ยท 94K views

Easily Control Cameras with Cinemachine in Unity!
Code Monkey ยท 103K views

Did AI Just Change Movies Forever?
ErikDoesVFX ยท 9.3M views

How to do Character Customization! (4 Methods, Unity Tutorial for Beginners)
Code Monkey ยท 202K views

What are Events? (C# Basics)
Code Monkey ยท 476K views

Steam EXPERT teaches you Game Marketing for SUCCESS in 2027!
Code Monkey ยท 2.1K views

Unity 6.3 LTS Beginner Tutorial #16 | Moving Platforms & Fall Damage
Crazy Carrot Studios ยท 21 views

Kickstart your game with First and Third Person Controllers! (FREE Unity Starter Assets)
Code Monkey ยท 210K views