These series are so good. Not too noobish but advanced enough for a person that knows programming but hasn't made games. Gives general idea of what to look into and figure out why.
The tutorials are great. But someone who is really interested in the programming aspect, I would like a little explanation on the programming side. The "Why" is more important to me rather then just do this and it works.
There is an error with the auto braking, if your stopping distance is below ~3 unity will sometimes forget about it altogether and you will end up inside the sphere. Just turn off autobraking when you set the stopping distance, and turn it back on when you unfocus.
I just managed to get everything working without an issue on the second try, lol. Thank you so much for the information packed content. Took me some time to get my head around it but the process of making the game is so satisfying! Thank you so much for making these tutorials, I'm sure a lot of games in the future will owe their existence to this playlist!
Wow, this tutorial got advanced pretty fast. Gotta say, your videos are packed with content and everything is thoroughly prepared from your side which is a lot. I've seen Udemy courses which don't even come close to this quality, so thanks a lot! Also thanks to everyone who supports you on Patreon.
Awesome tutorial! I managed to convert this to work on my 2D game. The interactable script is the same but the player controller script is pretty much all changed.
Dipping into coding after a 14 year break. I really appreciate these videos, thank you man! Side note, is the max speed and efficiency a core programmer personality trait? I have yet to see a good coder that doesn't seem like he's on cocaine when he works haha. Hallowed be the space bar.
When you're incessantly rewriting code and testing it, you get used to where the buttons are and want to do it as quickly as possible so you can continue working, so I'd say yes, yes it is. ;)
Thought I should mention that when you set a boolean, you don't have to set it to false. A bool will always default to false when being declared. You should only initialize it if you want to set it to true by default. Keeps the code a bit cleaner.
I can officially confirm that the player controller has a Fundamental bug that is preventing the game from acting in 2021. I even took the code and modified it to be exactly like his on github. DO NOT BOTHER TRYING TO FINISH THIS IN 2021. Basically the error that fundamentally prevents some of the advanced parts of the controller code, and will not interact with the object. I am going to try and download the finished version from git, and see if that even works.
this is the first time i see this power of codeing and the idea of wt you do is clear and you let us now wt you do and its like easy thx man i new here and i happy to see your work
For those the gizmos wire sphere doesn't show up yellow color, i use function OnDrawGizmos() private void OnDrawGizmos() { Gizmos.color = Color.yellow ; Gizmos.DrawWireSphere(transform.position, radius); }
If you are having an issue with the right click target, remember to remove the layer check on the conditional for the portion of the player controller where you right click.
Not sure if anyone is getting this, but I'm having trouble "focusing" on the interactable and I'm pretty sure I didn't leave anything out. This is what I have: [RequireComponent(typeof(playerMotor))] public class playerController : MonoBehaviour { public Interactable focus; Camera cam; playerMotor motor; void Start () { cam = Camera.main; motor = GetComponent(); } void Update () { if (Input.GetMouseButtonDown(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray,out hit)) { motor.MoveToPoint(hit.point); RemoveFocus(); } } if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray,out hit)) { Interactable interactable = hit.collider.GetComponent(); if (interactable != null) { SetFocus(interactable); } } } } void SetFocus(Interactable newFocus) { focus = newFocus; motor.MoveToPoint(newFocus.transform.position); } void RemoveFocus() { focus = null; } }
you have to add 100 behind the ray like this if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray,out hit, 100))
@@wildlifegmd2422 thank you, god bless u, i just figured it out how the f i cannot select the sphere, then i tried to change the layer to a ground. and its magically happened.
Wouldn't it be more robust to implement an interactable interface? That way interactable functionality can be added more flexibly without having to derive from the same class.
@@alexmyshinsky9474 I believe CPTANT is talking about an interface as in the programming technique, not a GUI element. An interface in C# is a specific programming feature that could potentially be used instead of making a parent class to inherit from.
Oh Mister Brakey.....I been trying to learn Unity for a while now an kind of understand the tutorials but sheeeeeeeeeeeet you do go through it real fast so I slow the play back speed and you sound real cool as a darlek... Keep up the good work.
He is already doing things in the most efficient and easy way for people to understand, I could make this tutorial way harder but the code run faster. I do know what you mean by "easy", but the code will be not clean, not efficient and run slow.
hey buddy. I dont think you should put the stopping distance in the stop followind target() back to 0f. You should always want your stopping distance to be the same (non changing). just saying. THX for the amazing videos
Thanks, Brackeys :) Your videos are amazing. Always smiling and with a positive attitude - that makes a great teacher. Thank You, Sensei and Master of Unity :) [If somebody needs.... Problems with a rotation -> As I was moving the sphere around the character, I began to notice that the character did not rotate. It rotates when I move with the left-click but not when following the interact-able with right-click. Solution (for my case) -> I completely forgot to add FaceTarget(); to the void Update() section.]
everytime I start learning from a new tutorial series I am usually a bit confused, and after finishing the entire tutorial series and comes back thinking "oh, this make so much sense "
I just click away because a function called interactable with an argument called interactable containing a variable class named interactable and an instance of it called interactable when creating an interactable object turns my brain to mush.
didn't first get the Focus set to sphere when clicking it, but started working after i changed Sphere's Layer to Ground.. idk how wrong it is, but just glad to see something happen :D
I ended up getting stuck on the player not moving after it focused the sphere. The problem seemed to be that I wrote updatePosition, instead of updateRotation. I believe I pressed enter to auto fill it, took a bit to find the problem since it was throwing no errors.
Great tutorial! I do have one thing wrong. When i click on the sphere it doen show up in the inspector under player. When i drag it in there and click somewhere else it disappears so the defocus works in just cant get it to focus. I put on the ground layer and it didnt work also tried static also didnt work anyone have the same issue?
Ran into an interesting error thought i would share the fix. sometimes i would get an error saying "Look rotation viewing vector is zero." it would just spam the console. Usually .normalized should make it so this doesnt happen but if the number is really small unity makes it 0 instead of 1/ so to fix this I added an if statement before the look rotation and it ended up looking like this. void FaceTarget () { Vector3 direction = (target.position - transform.position).normalized; if (direction.x != 0f || direction.z != 0f) { Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0f, direction.z)); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed); }
THANK YOU! I found some resources online that gave a similar solution but I couldn't figure out the exact conditions in the if statement. This was also the only issue I had in his tutorials
***SOLVING THE PROBLEM OF INTERACTION WITH THE SPHERE *** Unfortunately, this was not mentioned in this video and is very important for the correct operation of the script! When you insert a 3D Sphere object into the scene, it has a "default" layer marked in the inspector. For the interaction to work properly, you must change its layer to the same one as "Ground"
for anyone wanting to do this by the end of the year who've just started, don't bother with raycasts and shit. just use a collision and pass the collider to the player script using OnTrigger2D round an area, and cast the collider object as the player script.
@@hexadecimals1093 if you put a big collision box ONTOP of your actual collision box for a door/chest/thing-to-interact-with, you can check in your player script for "OnTriggerEnter2D" (tick isTrigger for collider). This means you can store the object that you can interact with from there (look up Collision structure)
This works up until you put the FollowTarget logic inside a check to see if Focus != null like this: void SetFocus(Interactable newFocus) { if(newFocus != Focus) { if (Focus != null) { print("Running focus"); Focus.OnDefocused(); Focus = newFocus; motor.FollowTarget(newFocus); } } It wil pass the first check but Focus is equal to null because its not declared with anything. So it wont activate the FollowTarget method. It instead goes to newFocus.OnFocused(transform); which doesnt return anything hence Focus will never be not null. Any ideas on how to fix?
dude your videos are awesome! If i had one piece of feedback its that you talk / type very fast at some points and i need to constantly go back a few seconds to take in what you said lol Other than that they're great! Keep it up
EDit: I drew a Sphere instead of a WireSphere lol but either way..something you could implement in a game somehow I'm sure; couldn't see through interactable Radius bubble.... but if you want to change color/alpha easily in the Editor window, In the Interactable script make a public Color radiusColor; then in OnDrawGizmosSelected() { Gizmos.Color = radiusColor;}
when i go into play mode and click on sphere my player doesnt detect it as a focus. what have i done wrong? It will not focus it, it will not follow it, the player just does nothing when i click or it walks through the sphere's space when i left click. EDIT: I fixed it. the sphere needs to be on the ground layer :)
You could create a bool for special interaction and create a get method that will return interaction transform if bool is true or own transform if the bool is false
I know this wouldnt be as good as a tutorial, but you can look up the unity docs on XML output as a starting point. E.g. output your player's transform to a file and read it on start.
I built my own terrain out of simple shapes and after following along some more I suddenly couldn't get the code to register the main plane anymore, so the entire walking code failed. For anyone suffering a similar issue: Just delete your ground and plop down a new one and bake a new navmesh. I tried for hours to find the slightest typo before realizing it was not the code that was jank, but the terrain.
Maybe someone still reads this, i have a Problem after clicking the Interactable. At first my Player moves at exactly the same position i clicked but after i Interacted i have somekind of not clickable parts around my player. I can not move him if i click at a Distance of 1.6 or less. I tested this by meassuring the distance between my hit.point and my player.position. If someone has any Idea where the problem is please help.
While I love brackeys and find them helpful, I dont know how to even start going about an interaction script. Using a player asset that came precoded to walk using WASD which is great cause I dont want to do a point and click game, but since Brackeys interaction code references its own movement script idk what to do
Woohoo, I'm so excited to continue working on this game! Currently I have run into an issue with the "Interactable" object. The error I'm getting is CS0103: the name "Interactable" does not exist in the current context. Any suggestions?
If the yellow wireframe doesn't appear for you, then your script might have an error. Check the console tab to see what the error is. If there is no error, you may have spelled the method name incorrectly. OnDrawGizmosSelected has two s's
If anyone is having a problem with the player not going from None(Interactable) to Sphere(Interactable), for me it worked when I added the FollowTarget function. I have no idea why.
I think I broke something, after i right click on the sphere, If I right click on the terrain I don't move anymore. *Update: I think i found the issue, in PlayerController.CS in the press right mouse button down logic... I commented out : if (interactable != null) { SetFocus (interactable); } That seemed to resolve the issue.
If you look at this script github.com/Brackeys/RPG-Tutorial/blob/master/RPG%20Project/Assets/Scripts/PlayerController.cs * * Note: ignore lines 25 & 26 (it's for a later tutorial) It looks like the functionality has changed on the right cliick, there is no... motor.MoveToPoint(hit.point); it's only part of the left click, looks like left is going to be for moving and right is going to be for picking up items. So remove motor.MoveToPoint(hit.point); from your right click and you should be caught up (it's likely something that is addressed in a future tutorial. hope that helps.
bro i have the same issue i need ur help apparently unity says NullReferenceException: Object reference not set to an instance of an object PLayermotor.FaceTarget () (at Assets/Scripts/PLayermotor.cs:48) PLayermotor.MoveToPoint (Vector3 point) (at Assets/Scripts/PLayermotor.cs:30) PlayerController.Update () (at Assets/Scripts/PlayerController.cs:25)
So I got to where I can click to set focus but it wont focus on what I right click on. Ran a debug and it was in fact clicking on things. I'm thinking it's because of the layerMask... and it was... so this is an odd issue - I have to set the sphere to ground layer for it to not be ignored.
At point 8:32 in the video I am getting the error message "NullReferenceException: Object reference not set to an instance of an object" I believe this being caused by the 'Focus' Interactable, because when I right click the sphere the error is no longer logged, and when I deselect the sphere the error is logged again. Is there a way for me to fix this? Or am I stuck with it?
Great tutorials! I have though a problem, I cannot select the Spehere on the Default Layer, it only works if it is part of the Ground layer. It eludes me why it is like that, from your video it looks fine on the Default layer. The movement mask seems to have no impact on your interactables.
I had the same problem as well and i just made a different layer called Interactables and on player movement mask i made it so that it had Ground and Interactables selected, seems to work fine now but im not sure if it will break in the future. hopefully that helps ya!
Hey so i messed around with it further and if you copied the if statement for movement like he did and only changed the GetMouseButtonDown, make sure to delete the movementMask in the arguments of the if statement for physics.Raycast! this will make it so that when checking for interactables it wont be solely be based on the ground layer and check any object in the scene.
thank you! i just spent 30 minutes looking through my code because i was certain i missed a semicolon or accidentally misspelled a variable or something to make my right mouse button not work.
Additional Request for the future, is there any chance you could look into performance management on completion of this project? I'm talking about how you'd swap between low and high poly models, terrain and assets based on distance (whether to use Async-scenes or to run checks through script(s) checking object distances. I get this doesn't really fit to the scale of the project (at least the intro footage shows a relatively small environment, such that scene management probably won't be a problem). Just a request for features that may have been forgotten/left out of this tutorial due to its scope. I look following this tutorial in the near future. Keep up the awesome work!
Take a look at tutorials for Occlusion Culling and LOD (Level of Detail). Both of these are built into Unity (although there are slight shit tbh when it comes to clean use of them). I don't fully understand why you would want to use Async to check object distance? If you want to keep it efficient, run it on a separate thread. :P
ChumperDumper when I first started learning about scene management, I wound up on a tutorial suggesting breaking up a scene through Async-loading different sections of the scene based off hitboxes (so for example, loading the other side of a bridge as you start to cross it, removing the scene where you came from as you leave the far side of the bridge). It's just one way of keeping the object-count low in a large world. I hadn't heard of the Occlusion Culling and LOD settings built into Unity before reading your comment (I honestly thought there was no built-in features for asset-detail management), so I'll go research them now. Thanks!
No one may ever see this but it is worth a shot. So I am currently following this tutorial and the StopFollwingTarget section is not working. If anyone has any ideas or has found a solution I would love to here them. Thanks
the problem for so that the player did not move on rigth click was that i wrote agent.updatePosition instead of agent.updateRotation in methods FollowTarget & StopFollowingTarget
Gone through it twice, assuming its a version problem; but has anyone found that the system works perfectly, except once I've interacted with something (prints debug.log("INTERACT")), I cant interact with it again, even when I removed the focus, even when I focus on a new object with the interactable script?
When your watching a tutorial series for the inventory and you have to make sure that your FPS controller doesn’t moving the wrong direction because you shot an interactable.
One question - why make an Intractable parent class for all the stuff that probably has nothing else in common? Doesn't it make more sense to make something like an interface? Is that even possible in unity? I'm coming from UE4 perspective, so this approach with attaching scripts to objects is still weird to me.
For those who had a problem interacting with the mouse right click (to appear on the Focus box), try setting the esphere to Ground, hope im doing the right thing, if im wrong please leave a comment
the radius will not show in the inspector using UnityEngine; [SerializeField] public class NewBehaviourScript : MonoBehaviour { public float radius = 3; void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(transform.position, radius); } }
i dont know how far you are :P void OnDrawGizmosSelected() { if (interactionTransform == null) interactionTransform = transform; Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(interactionTransform.position, radius); } or void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; Gizmos.DrawWireSphere(interactionTransform.position, radius); }
Alright! Great work on your videos! If you were to make text-based Unity tutorials, I would gladly become a Patreon supporter. Unity is in dire need of more HQ text-based tutorials.
the .Slerp function allows the Quaternion to eat hot soup with out burning its mouth.
Y E S
Lmfaoooo
@AstroFahl Parent may have no mouth
wtf
i wrote good code and sphere not working how fix it???
These series are so good. Not too noobish but advanced enough for a person that knows programming but hasn't made games. Gives general idea of what to look into and figure out why.
I know I'm actually progressing when a Brackeys video starts to make sense
i wrote good code and sphere not working how fix it???
When you follow along perfectly with a unity tutorial
Unity: YOU ARE WRONG NOW SUFFER
oww yes i know what you mean XD
You might be running a different version of Unity, or a different version of C#
I feel more comfortable playing Russian roulette, at least I've never failed at that.
@@dibaterman you never lose, until you do, but then you can never lose ever again
i wrote good code and sphere not working how fix it???
The tutorials are great. But someone who is really interested in the programming aspect, I would like a little explanation on the programming side. The "Why" is more important to me rather then just do this and it works.
i wrote good code and sphere not working how fix it???
I'm pretty sure that a Quaternion Slerper is the final boss in some game... Something in the Sci-fi horror genre...
It's the final boss of coding.
There is an error with the auto braking, if your stopping distance is below ~3 unity will sometimes forget about it altogether and you will end up inside the sphere. Just turn off autobraking when you set the stopping distance, and turn it back on when you unfocus.
I just managed to get everything working without an issue on the second try, lol. Thank you so much for the information packed content. Took me some time to get my head around it but the process of making the game is so satisfying! Thank you so much for making these tutorials, I'm sure a lot of games in the future will owe their existence to this playlist!
Whoah! The quality of this tutorial is top notch. Thanks Brackeys!
For those the gizmos wire sphere doesn't show up, can try to include the "using System.Collections" tag in Interactable
I am using 2019.4.4f1
The fix for me was changing
void OnDrawGizmoSelected ()
to
void OnDrawGizmos ()
As a beginner, this was a tough one, a lot of just rewriting, but it all came together in the end. Thanks!
For anybody having a 'null' Interactable error when clicking the sphere, try removing the LayerMask from the Physics.Raycast parameters.
thx bro
Thanks alot!
Mine problem was however calling OnDefocused twice inside SetFocus
Thank, You. saved me alot of time here mate
Most underrated comment
Wow, this tutorial got advanced pretty fast. Gotta say, your videos are packed with content and everything is thoroughly prepared from your side which is a lot. I've seen Udemy courses which don't even come close to this quality, so thanks a lot! Also thanks to everyone who supports you on Patreon.
i wrote good code and sphere not working how fix it???
Awesome tutorial! I managed to convert this to work on my 2D game. The interactable script is the same but the player controller script is pretty much all changed.
man makes top tier things look so simple im scared for this man's power tbh
I love this man from the bottom of my heart
Dipping into coding after a 14 year break. I really appreciate these videos, thank you man!
Side note, is the max speed and efficiency a core programmer personality trait? I have yet to see a good coder that doesn't seem like he's on cocaine when he works haha. Hallowed be the space bar.
When you're incessantly rewriting code and testing it, you get used to where the buttons are and want to do it as quickly as possible so you can continue working, so I'd say yes, yes it is. ;)
@@MisterShnig i wrote good code and sphere not working how fix it???
Thought I should mention that when you set a boolean, you don't have to set it to false. A bool will always default to false when being declared. You should only initialize it if you want to set it to true by default. Keeps the code a bit cleaner.
Setting it to false makes it easier to understand for others! And it doesn't muddle up the code that much..
I can officially confirm that the player controller has a Fundamental bug that is preventing the game from acting in 2021. I even took the code and modified it to be exactly like his on github. DO NOT BOTHER TRYING TO FINISH THIS IN 2021. Basically the error that fundamentally prevents some of the advanced parts of the controller code, and will not interact with the object. I am going to try and download the finished version from git, and see if that even works.
still the best and shortest tutorial :D
I had some coding projects due last minute. Thanks, Brackeys, You guys make coding so easy!
this is the first time i see this power of codeing and the idea of wt you do is clear and you let us now wt you do and its like easy thx man i new here and i happy to see your work
great series, you are definitely my go to for learning unity stuff!! practical, comprehensive and pleasant, thanks!
For those the gizmos wire sphere doesn't show up yellow color, i use function OnDrawGizmos()
private void OnDrawGizmos()
{
Gizmos.color = Color.yellow ;
Gizmos.DrawWireSphere(transform.position, radius);
}
i wrote good code and sphere not working how fix it???
You are the King of Unity :) All of your tutorials are so good and very understandable. Thank you a lot Sir!
i wrote good code and sphere not working how fix it???
If you are having an issue with the right click target, remember to remove the layer check on the conditional for the portion of the player controller where you right click.
Thank you, I was looking for this!
Great pace of the tutorial.
Not sure if anyone is getting this, but I'm having trouble "focusing" on the interactable and I'm pretty sure I didn't leave anything out. This is what I have:
[RequireComponent(typeof(playerMotor))]
public class playerController : MonoBehaviour {
public Interactable focus;
Camera cam;
playerMotor motor;
void Start () {
cam = Camera.main;
motor = GetComponent();
}
void Update () {
if (Input.GetMouseButtonDown(1))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
motor.MoveToPoint(hit.point);
RemoveFocus();
}
}
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
Interactable interactable = hit.collider.GetComponent();
if (interactable != null)
{
SetFocus(interactable);
}
}
}
}
void SetFocus(Interactable newFocus)
{
focus = newFocus;
motor.MoveToPoint(newFocus.transform.position);
}
void RemoveFocus()
{
focus = null;
}
}
you have to add 100 behind the ray like this
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit, 100))
@@wildlifegmd2422 thank you, god bless u, i just figured it out how the f i cannot select the sphere, then i tried to change the layer to a ground. and its magically happened.
Fikri Lazzuardi I was so stuck until I read this. Thanks
AHA! In 10:38 you said "on defocused" when you wrote "new focus"! I KNEW NOONE COULD BE THAT GODLY AS TO BE PERFECT IN EVERY SINGLE WAY!
You are just awsome.recently i am working on a cool open world game project . i have learnt a lot from you
Wouldn't it be more robust to implement an interactable interface?
That way interactable functionality can be added more flexibly without having to derive from the same class.
In case of NPC's interact with objects, they wont be able to use interface, you know ;)
@@alexmyshinsky9474 I believe CPTANT is talking about an interface as in the programming technique, not a GUI element. An interface in C# is a specific programming feature that could potentially be used instead of making a parent class to inherit from.
@@alexmyshinsky9474 Generally in Brackeys tutorial, he does the optimizing stuff later. Idk if he has done it for this though.
Since you are doing a collab with Seb, can you show you two using the new Unity Collaboration system?
KaletheQuick was the day you were going to come home
@@jamesiagary1388 What are you talking about? lol tf
Oh Mister Brakey.....I been trying to learn Unity for a while now an kind of understand the tutorials but sheeeeeeeeeeeet you do go through it real fast so I slow the play back speed and you sound real cool as a darlek... Keep up the good work.
I noticed something in your tutorials, you choose the hardest way to do things. I know you love maths and complexity but you should keep it simple.
He is already doing things in the most efficient and easy way for people to understand, I could make this tutorial way harder but the code run faster. I do know what you mean by "easy", but the code will be not clean, not efficient and run slow.
hey buddy. I dont think you should put the stopping distance in the stop followind target() back to 0f. You should always want your stopping distance to be the same (non changing). just saying. THX for the amazing videos
Thanks, Brackeys :) Your videos are amazing. Always smiling and with a positive attitude - that makes a great teacher. Thank You, Sensei and Master of Unity :)
[If somebody needs....
Problems with a rotation -> As I was moving the sphere around the character, I began to notice that the character did not rotate. It rotates when I move with the left-click but not when following the interact-able with right-click.
Solution (for my case) -> I completely forgot to add FaceTarget(); to the void Update() section.]
Omfg you saved my life (and my computer), I've been stuck on this for hours, thank you!
everytime I start learning from a new tutorial series I am usually a bit confused, and after finishing the entire tutorial series and comes back thinking "oh, this make so much sense "
I just click away because a function called interactable with an argument called interactable containing a variable class named interactable and an instance of it called interactable when creating an interactable object turns my brain to mush.
I've been looking for this for so long, thank you so much!
didn't first get the Focus set to sphere when clicking it, but started working after i changed Sphere's Layer to Ground..
idk how wrong it is, but just glad to see something happen :D
delete movement mask from the other one
If you are using cinemachine virtual camera and raycasting is not working, try using the FixedUpdate() method instead of Update()
After my exams I will start working thorugh this!
Also started making tutorials about 2D stuff in Unity, you are a great inspiration Brackeys!
what?
He probably means you're hot xD
(which you are, tbh)
Loveless Tsukashi okay 😅 thank you ?
Np haha checked your tutorial and you also have a beautiful voice and good content to teach. So, +1 subscriber!
Loveless Tsukashi cool thanks! Maybe I should start show myself like brackeys 😂
Thanks for making this series now I can make my own RPG game!
I ended up getting stuck on the player not moving after it focused the sphere. The problem seemed to be that I wrote updatePosition, instead of updateRotation. I believe I pressed enter to auto fill it, took a bit to find the problem since it was throwing no errors.
Bookmark 6:28, also thanks, Brackeys, for the good video
Great tutorial! I do have one thing wrong. When i click on the sphere it doen show up in the inspector under player. When i drag it in there and click somewhere else it disappears so the defocus works in just cant get it to focus. I put on the ground layer and it didnt work also tried static also didnt work anyone have the same issue?
I have the same problem
If anyone still facing the same issue, remove movementLayer from if statement in right mouse click section. Worked for me.
Ran into an interesting error thought i would share the fix. sometimes i would get an error saying "Look rotation viewing vector is zero." it would just spam the console. Usually .normalized should make it so this doesnt happen but if the number is really small unity makes it 0 instead of 1/ so to fix this I added an if statement before the look rotation and it ended up looking like this.
void FaceTarget ()
{
Vector3 direction = (target.position - transform.position).normalized;
if (direction.x != 0f || direction.z != 0f)
{
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0f, direction.z));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
}
}
This is the only issue I have ran into since following his tutorials. Thanks :p
Dude thank you! i had no clue what was wrong!
Thanks so much, it means a lot!
thanks
THANK YOU! I found some resources online that gave a similar solution but I couldn't figure out the exact conditions in the if statement. This was also the only issue I had in his tutorials
For those who is right clicking on the object and nothing happens, try putting the right click method above the left click method
***SOLVING THE PROBLEM OF INTERACTION WITH THE SPHERE ***
Unfortunately, this was not mentioned in this video and is very important for the correct operation of the script!
When you insert a 3D Sphere object into the scene, it has a "default" layer marked in the inspector. For the interaction to work properly, you must change its layer to the same one as "Ground"
for anyone wanting to do this by the end of the year who've just started, don't bother with raycasts and shit. just use a collision and pass the collider to the player script using OnTrigger2D round an area, and cast the collider object as the player script.
how do i do that
@@hexadecimals1093 if you put a big collision box ONTOP of your actual collision box for a door/chest/thing-to-interact-with, you can check in your player script for "OnTriggerEnter2D" (tick isTrigger for collider). This means you can store the object that you can interact with from there (look up Collision structure)
@@roganjosh6220OMG dude you ARE a legend. Thank you man!
I really love the clicking and typing sound :)
This works up until you put the FollowTarget logic inside a check to see if Focus != null like this: void SetFocus(Interactable newFocus) {
if(newFocus != Focus) {
if (Focus != null) {
print("Running focus");
Focus.OnDefocused();
Focus = newFocus;
motor.FollowTarget(newFocus);
}
}
It wil pass the first check but Focus is equal to null because its not declared with anything. So it wont activate the FollowTarget method. It instead goes to newFocus.OnFocused(transform); which doesnt return anything hence Focus will never be not null. Any ideas on how to fix?
Not sure if it will help anyone now but don't forget to add the Intractable Script to the Sphere. :)
dude your videos are awesome!
If i had one piece of feedback its that you talk / type very fast at some points and i need to constantly go back a few seconds to take in what you said lol
Other than that they're great! Keep it up
EDit: I drew a Sphere instead of a WireSphere lol but either way..something you could implement in a game somehow I'm sure;
couldn't see through interactable Radius bubble.... but if you want to change color/alpha easily in the Editor window, In the Interactable script make a public Color radiusColor; then in OnDrawGizmosSelected() { Gizmos.Color = radiusColor;}
Still works for me so far thanks
when i go into play mode and click on sphere my player doesnt detect it as a focus. what have i done wrong? It will not focus it, it will not follow it, the player just does nothing when i click or it walks through the sphere's space when i left click.
EDIT: I fixed it. the sphere needs to be on the ground layer :)
This helped. I was losing my mind. Thanks :)
Thanks
delete movement Mask
You could create a bool for special interaction and create a get method that will return interaction transform if bool is true or own transform if the bool is false
Hi Brakeys, your tutorials are awesome, I learn so much!!! Please can you do a save system tutorial?
I know this wouldnt be as good as a tutorial, but you can look up the unity docs on XML output as a starting point. E.g. output your player's transform to a file and read it on start.
Y'all, check out PlayerPrefs. It's super easy!
YAY i was waiting 7 years for this
I don't know if anyone is still watching these, but my player stops moving after the interaction, any idea why?
Same issue. If you figured it out I'd love to hear what you found.
Why don't you use colliders(as triggers) with their methods OnTriggerEnter, OnTriggerExit for interactables?
:D exactly what i used to do lol
I need Help! My player sets the sphere to interactible in the public float but does not follow it, how do I fix this?
I've got the same problem....anybody please help
Same, have you got a fix?
Thanks For You Teacher I've made everything True With Your Helps Really Thanks
All Your lessons are really helpfull even if I live in Russia !!)) Thanks!!
live Japan,too!
I built my own terrain out of simple shapes and after following along some more I suddenly couldn't get the code to register the main plane anymore, so the entire walking code failed.
For anyone suffering a similar issue: Just delete your ground and plop down a new one and bake a new navmesh. I tried for hours to find the slightest typo before realizing it was not the code that was jank, but the terrain.
Maybe someone still reads this, i have a Problem after clicking the Interactable. At first my Player moves at exactly the same position i clicked but after i Interacted i have somekind of not clickable parts around my player. I can not move him if i click at a Distance of 1.6 or less. I tested this by meassuring the distance between my hit.point and my player.position. If someone has any Idea where the problem is please help.
Could it possibly be that your clicking on your players collider
While I love brackeys and find them helpful, I dont know how to even start going about an interaction script. Using a player asset that came precoded to walk using WASD which is great cause I dont want to do a point and click game, but since Brackeys interaction code references its own movement script idk what to do
oneyear too late :D i think you need to take input andjust add to transform of the object idk im just learning stuff
agent.StopingDistance is not working.... My player wont stop when he reach the radius of the enemy... Any ideas?
the interactables need a collider for this to work FYI
Woohoo, I'm so excited to continue working on this game! Currently I have run into an issue with the "Interactable" object. The error I'm getting is CS0103: the name "Interactable" does not exist in the current context. Any suggestions?
It would be easier to find the reason of error if you could specify the line where the error is being generated.
u missed the part on 14:10 where he tells you to use the own transform object from the circle as his interaction transform
If the yellow wireframe doesn't appear for you, then your script might have an error. Check the console tab to see what the error is. If there is no error, you may have spelled the method name incorrectly. OnDrawGizmosSelected has two s's
Gizmos is working but my player did not stoping when he reach the radius of the enemy...
If anyone is having a problem with the player not going from None(Interactable) to Sphere(Interactable), for me it worked when I added the FollowTarget function. I have no idea why.
@5:32 why do we set the argument of FollowTarget to newFocus instead of the variable focus that we declared right above it?
I've been waiting for something like this, thanks!
Ep 2!!! Thanks Brackeys :D
how can u be such an awesome teacher ??
I think I broke something, after i right click on the sphere, If I right click on the terrain I don't move anymore.
*Update: I think i found the issue, in PlayerController.CS
in the press right mouse button down logic...
I commented out :
if (interactable != null)
{
SetFocus (interactable);
}
That seemed to resolve the issue.
Same issue. If you comment that line out you no longer interact with the Object.. Curious what I did wrong
If you look at this script
github.com/Brackeys/RPG-Tutorial/blob/master/RPG%20Project/Assets/Scripts/PlayerController.cs
* * Note: ignore lines 25 & 26 (it's for a later tutorial)
It looks like the functionality has changed
on the right cliick, there is no...
motor.MoveToPoint(hit.point);
it's only part of the left click, looks like left is going to be for moving and right is going to be for picking up items.
So remove motor.MoveToPoint(hit.point); from your right click and you should be caught up (it's likely something that is addressed in a future tutorial.
hope that helps.
bro i have the same issue i need ur help apparently unity says
NullReferenceException: Object reference not set to an instance of an object
PLayermotor.FaceTarget () (at Assets/Scripts/PLayermotor.cs:48)
PLayermotor.MoveToPoint (Vector3 point) (at Assets/Scripts/PLayermotor.cs:30)
PlayerController.Update () (at Assets/Scripts/PlayerController.cs:25)
Code seems to match perfectly but i can not left click on the item, focus on it, and have him move to it. It focuses, just will not move.
I have the same issue. Pretty frustrating.
Why Brackeys is so awesome?
9:55, check if player is in range
for those saying its to fast paced, pause at every line of code and write it up.
So I got to where I can click to set focus but it wont focus on what I right click on. Ran a debug and it was in fact clicking on things. I'm thinking it's because of the layerMask... and it was... so this is an odd issue - I have to set the sphere to ground layer for it to not be ignored.
At point 8:32 in the video I am getting the error message "NullReferenceException: Object reference not set to an instance of an object"
I believe this being caused by the 'Focus' Interactable, because when I right click the sphere the error is no longer logged, and when I deselect the sphere the error is logged again.
Is there a way for me to fix this? Or am I stuck with it?
Great tutorials! I have though a problem, I cannot select the Spehere on the Default Layer, it only works if it is part of the Ground layer. It eludes me why it is like that, from your video it looks fine on the Default layer. The movement mask seems to have no impact on your interactables.
I had the same problem as well and i just made a different layer called Interactables and on player movement mask i made it so that it had Ground and Interactables selected, seems to work fine now but im not sure if it will break in the future. hopefully that helps ya!
Hey so i messed around with it further and if you copied the if statement for movement like he did and only changed the GetMouseButtonDown, make sure to delete the movementMask in the arguments of the if statement for physics.Raycast! this will make it so that when checking for interactables it wont be solely be based on the ground layer and check any object in the scene.
Guys!I've just found that Interactable objects need to be on Ground layer!
Or you can remove the movementmask variable on your "if" argument since that is the one trapping the layermask.
thank you! i just spent 30 minutes looking through my code because i was certain i missed a semicolon or accidentally misspelled a variable or something to make my right mouse button not work.
But it still wont stop when the player reach the edge of the radius of the interactable object..
Additional Request for the future, is there any chance you could look into performance management on completion of this project? I'm talking about how you'd swap between low and high poly models, terrain and assets based on distance (whether to use Async-scenes or to run checks through script(s) checking object distances.
I get this doesn't really fit to the scale of the project (at least the intro footage shows a relatively small environment, such that scene management probably won't be a problem). Just a request for features that may have been forgotten/left out of this tutorial due to its scope.
I look following this tutorial in the near future. Keep up the awesome work!
Take a look at tutorials for Occlusion Culling and LOD (Level of Detail). Both of these are built into Unity (although there are slight shit tbh when it comes to clean use of them). I don't fully understand why you would want to use Async to check object distance? If you want to keep it efficient, run it on a separate thread. :P
Running it on a separate thread would, by definition, make it asynchronous.
ChumperDumper when I first started learning about scene management, I wound up on a tutorial suggesting breaking up a scene through Async-loading different sections of the scene based off hitboxes (so for example, loading the other side of a bridge as you start to cross it, removing the scene where you came from as you leave the far side of the bridge). It's just one way of keeping the object-count low in a large world.
I hadn't heard of the Occlusion Culling and LOD settings built into Unity before reading your comment (I honestly thought there was no built-in features for asset-detail management), so I'll go research them now. Thanks!
for people using 2019 unity + the code is not working you have to use 2018 (at least i hope so)
No one may ever see this but it is worth a shot. So I am currently following this tutorial and the StopFollwingTarget section is not working. If anyone has any ideas or has found a solution I would love to here them. Thanks
the problem for so that the player did not move on rigth click was that i wrote
agent.updatePosition
instead of
agent.updateRotation
in methods FollowTarget & StopFollowingTarget
thanks man
Gone through it twice, assuming its a version problem; but
has anyone found that the system works perfectly, except once I've interacted with something (prints debug.log("INTERACT")), I cant interact with it again, even when I removed the focus, even when I focus on a new object with the interactable script?
Love your videos!!! Can you do video about copyright, and how to protect your games or assets. Thanks a lot :)
When your watching a tutorial series for the inventory and you have to make sure that your FPS controller doesn’t moving the wrong direction because you shot an interactable.
One question - why make an Intractable parent class for all the stuff that probably has nothing else in common? Doesn't it make more sense to make something like an interface? Is that even possible in unity?
I'm coming from UE4 perspective, so this approach with attaching scripts to objects is still weird to me.
For those who had a problem interacting with the mouse right click (to appear on the Focus box), try setting the esphere to Ground, hope im doing the right thing, if im wrong please leave a comment
Question: Why did you not use 'Transform.LookAt' instead of creating your own version of it?
Transform.LookAt would snap the rotation. Doing it his way with slerp lets us do it smoothly at our specified speed
the radius will not show in the inspector
using UnityEngine;
[SerializeField]
public class NewBehaviourScript : MonoBehaviour {
public float radius = 3;
void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, radius);
}
}
did you make it a public
i dont know how far you are :P
void OnDrawGizmosSelected()
{
if (interactionTransform == null)
interactionTransform = transform;
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(interactionTransform.position, radius);
}
or
void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(interactionTransform.position, radius);
}
your public class, you need to change this name to your script name. you have NewBehaviourScript, change this
The issue is it's 3f; not just 3;
Alright! Great work on your videos!
If you were to make text-based Unity tutorials, I would gladly become a Patreon supporter. Unity is in dire need of more HQ text-based tutorials.
This is such a good tutorial. Now I just need to go watch some coroutine videos...
How can we do to interact with an item by pressing F for example instead of mouseclick please ?
I waited so long for this but it was worth it ;D