where we run controller.Move(dir * moveSpeed * Time.deltaTime); change the dir to dir.normalized to stop the character walking faster in diagonal directions Also in the AimStateManager class I assumed the xAxis and yAxis.Update(Time.deltaTime) would be frame rate independent, this is not the case… To fix this simply change these variables to floats which can be private and also add a [SerializeField] float mouseSense; In the Update function replace the xAxis and yAxis.Update code with xAxis +=(Input.GetAxisRaw(“Mouse X”) * mouseSense); yAxis -=(Input.GetAxisRaw(“Mouse Y”) * mouseSense); yAxis = Mathf.Clamp(yAxis,-80,80) The rest of the code will stay the same
When I tried to change xAxis and yAxis in the update, I was told that I couldn't convert Cinemachine. AxisState to float because I was new to it and didn't quite understand it
@@dantie7186 drive.google.com/file/d/1C2LoLNtjQWVlKYYnEhN7RT9QSTvQRNjH/view Here is the project files for Ep 5 also in the second episode I show where I change the axis states to floats discord.gg/FGnPBHHQsZ here’s my discord if u need any help still
Honestly mate I've been trying to get my own movement script and follow cam set up for like week now (I only started Unity 3 weeks ago and completely new to scripting) I've watched loaaads of youtube tuts and its either been too confusing or somethings messed up, whatever but this is literally the first video that I've been able to follow start to finish and actually understood what I've done by the end of it. Big thank you for these videos, subbed my guy.
I will cover jumping in the third video but if all you want is a simple character controller simply add a variable for jumpForce and in the update you can paste this code: if(IsGrounded()&&Input.getKeyDown(KeyCode.Space)) velocity.y += jumpForce;
8:00 Just want to add, I've heard it's not good practice to have multiple CharacterController.Move calls in a single update loop as it could potentially cause some instability issues (plus it's really easy to fix). So my solution is to remove the move call from GetDirectionAndMove and Gravity, the in the Update loop after both those methods are called, create a Vector3 finalMove which is the sum of dir * moveSpeed and velocity, then call controller.Move(finalMove * Time.deltaTime)
Thank you, episode 5 will be out later today and a lot of people seem to be enjoying it so I will be continuing to add things like enemy AI and a full gameplay loop by the end.
turn on the bell new videos coming soon, also I will be dropping the custom wheel collider and car controller asset for free and at some point will be adding cars to the project
im getting the error ArgumentException: Input Axis vertical is not setup and also the error:NullreferenceException: object reference not set to an instance of an object movementstatemanager.OnDrawGizmos() how do you fix these?? also this is for the movementstatemanager script
Super beginner question but how does he actually make it move was there a separate video for bindings? Is it with a controller or keyboard am lost honestly
So Unity has basic inputs pre set up so the Horizontal and Vertical axis for the keyboard and mouse are there for you to use and change as you wish. hope this answers your question :)
Do you have an updated AimStateManager Script for newer Cinemachine updates? I've been loving this tutorial but running into some issues particularly with the Axis. I put in the script you have (With changes "using Unity.Cinemachine;" instead of "using Cinemachine;) but AxisState is deprecated. I tried changing AxisState to InputAxis and get some errors I cant seem to get around. If I try to continue using the script as is, it still runs but when I run the game where you are at 14:08, x axis seems to work fine and the camera follows the mouse left to right but y axis doesnt seem to be registering. no up and down camera movement with all the same scripts as the vid. Are there any updates/fixes for this stuff? Thanks.
Can you help solve this error ? i dont know why but no error with 'Walk' and 'Crouch' and i stuck here. Error: \States\IdleState.cs(16,79): error CS1061: 'MovementStateManager' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'MovementStateManager' could be found (are you missing a using directive or an assembly reference?)
Make sure the variable or the RunState Class in the movement state manager is of type MovementBaseState. It seems like you may have it as a MovementStateManager class
Hi, i followed all the instructions but i think is the new input system. Look when i put everything and go to check i have a problem that says : Cannot modify the return value of 'Transform.position' because it is not a variable Please i need help. :(
Looks great. I plan to follow this tutorial but make a movable character for unity mobile (Coz I don't want to follow some tutorial deto copy and want to do some of the stuff myself. That's why choosing a different platform). Any advice you wanna give before I start following this series?
I did everything right but for some reason, I can't move my camera around whenever im moving the player but the player does move in the camera forward. How do i fix this
Crazy beginner question. I'm starting with this video and Googling loads at every step. After creating the Movement State Manager script your screen goes to the place you can type code. What coding program is that?
Whenever I add the ground layer and set the layer mask to it, my capsule still snaps/falls really fast. Has anyone else had this issue? Im on a slightly newer version of unity 2022.3.8
Tell me where I could have messed up, everything works for me, only the inversion on the y axis, when I move the mouse up, the character looks down and vice versa
here in this if we want that camera is alwys in d back side of character and follows character when on swipe we change camera angle than character angle must be same as camera...how this possible?
Is there a way to make the character rotate only after the camera reaches a certain angle? Trying to recreate Transformers fall of cybertron controls or like Minecraft 3rd person where your player rotates after a certain point
please help me I keep on getting an error saying that the variable controller for movement state manager has not been assigned. I'm a beginner and I don't know how to solve this on my own and it wont let me play the game until I fix it. Please help!!!
i keep getting the error Assets\MovementStateManager.cs(8,6): error CS0246: The type or namespace name 'hideinspectorAttribute' could not be found (are you missing a using directive or an assembly reference?) what to do?
i typed in everything that was given to me and i keep getting the same 3 errors. someone please help😭 edit; nvm i was able to get rid of them but got a new one. error cs0103L the name 'controller' does not exist in the current conect when should i do?
Bro I'm unable to use Mouse X and Y. I did every step that you did but it dont work. please if you have any idea what i could do pleaaaasee say it to me. thanks
i keep on getting errors that say Assets\MovementStateManager.cs(7,29): error CS1519: Invalid token '=' in class, record, struct, or interface member declaration
You don't even have to make a ground check. The Unity CharacterController has it's build in controller.isGrounded. You can just check that with an if statement and handle the rest of the logic in there.
I’m tempted to make a video on how to upgrade this project to the new Input system. But will probably continue the series with the old system due to simplicity
Thank you for reminding me I picked Unity back up after a few months break and saw they had a Unity 6 so I upgraded the project and realised the same thing so I will have to make a new video for the cinemachine update
That was my mums favourite part of the video, in the future I am going to edit it less so I will show that I am no genius and it takes time, effort and persistence. I am still learning and always will be
Hey Gadd, I followed every step of this video exactly but the character doesn't stop moving for a few more seconds even after I took my hands off the controls. Here's the code(If there's something that I did wrong, please tell me!): MovementStateManager.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class MovementStateManager : MonoBehaviour { public float movespeed = 3; float hzInput, vInput; [HideInInspector] public Vector3 dir; CharacterController controller; [SerializeField] float groundYOffset; [SerializeField] LayerMask groundMask; Vector3 spherePos; [SerializeField] float gravity = -9.81f; Vector3 velocity; void Start() { controller = GetComponent(); } void Update() { GetDirectionAndMove(); Gravity(); } void GetDirectionAndMove() { hzInput = Input.GetAxis("Horizontal"); vInput = Input.GetAxis("Vertical"); dir = transform.forward * vInput + transform.right * hzInput; controller.Move(dir.normalized * movespeed * Time.deltaTime); } bool IsGrounded() { spherePos = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z); if (Physics.CheckSphere(spherePos, controller.radius - 0.05f, groundMask)) return true; return false; } void Gravity() { if (!IsGrounded()) velocity.y += gravity * Time.deltaTime; else if (velocity.y < 0) velocity.y = -2; controller.Move(velocity * Time.deltaTime); } private void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(spherePos, controller.radius - 0.05f); } }
Yet another tutorial that doesn't work (probably due to Unity's constant annoying updates). It wouldn't let me add a CineMachine Virtual Camera unless I parented it to an object on the hierarchy and it's symbol doesn't appear next to the main camera and it doesn't function. I'm so sick of unity's bullcrap.
@@gaddgames Never Mind, I got it to work! For some reason, if I selected it in the Component Tab from the tab, it would be grayed out and not selectable unless I parented it to an object in the hierarchy, in which case it wouldn't work. However, when I right-clicked the Hierarchy and selected Cinemachine and virtual camera from there, it worked just as you showed. Thank you for your attempted support regardless!
i got some error that said: nullreferenceException: object reference not set to an instance of an object movementStateManager.OnDrawGizmos can someone help me
Go to file at the top left of Unity then preferences/ external tools, then select your IDE from the drop down menu then regenerate project files then it should make things easier to follow along with
@@gaddgames I did that now. its not that. there is something wrong with the assemblies not showing up for me for some reason. I had a fix for it but that doesn't seem to be an option for me sadly. do you have a discord?
Yes you can in the second episode which is out now I show you how to replace the model with the capsule and get the animations set up. Finally in the third episode I will be showing you how to write the code to change the animations depending if you are running, crouching or walking. If you have any questions feel free to message me on my discord which you can find on my website gadd.games
NullReferenceException: Object reference not set to an instance of an object MovementStateManagement.OnDrawGizmos () (at Assets/MovementStateManagement.cs:60) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) i have this problem how i can fix
ay man im stuck at 14:00 i cant play bc it automaticly pauses the game and when i try to unpause it gives me an error saying: System.ArgumentException: Input Axis Mouse Y is not setup. can you help me out please?
where we run controller.Move(dir * moveSpeed * Time.deltaTime); change the dir to dir.normalized to stop the character walking faster in diagonal directions
Also in the AimStateManager class I assumed the xAxis and yAxis.Update(Time.deltaTime) would be frame rate independent, this is not the case…
To fix this simply change these variables to floats which can be private and also add a [SerializeField] float mouseSense;
In the Update function replace the xAxis and yAxis.Update code with
xAxis +=(Input.GetAxisRaw(“Mouse X”) * mouseSense);
yAxis -=(Input.GetAxisRaw(“Mouse Y”) * mouseSense);
yAxis = Mathf.Clamp(yAxis,-80,80)
The rest of the code will stay the same
When I tried to change xAxis and yAxis in the update, I was told that I couldn't convert Cinemachine. AxisState to float because I was new to it and didn't quite understand it
If there is project source code, can you package it and send it to me for study? Thank you for a long time
@@dantie7186 drive.google.com/file/d/1C2LoLNtjQWVlKYYnEhN7RT9QSTvQRNjH/view
Here is the project files for Ep 5 also in the second episode I show where I change the axis states to floats
discord.gg/FGnPBHHQsZ here’s my discord if u need any help still
You can use Vector3.ClampMagnitude(dir, 1.0f)
instead of dir.normalized
cuz you will get some weird movement with dir.normalized
@@mrfun3340 thanks mate, this is what im looking for. i was using dir.normalized and it makes my player like walking on the ice
This is the best tutorial i ve ever seen!! Thank you man for this serie!!!
Thank you so much!
Honestly mate I've been trying to get my own movement script and follow cam set up for like week now (I only started Unity 3 weeks ago and completely new to scripting) I've watched loaaads of youtube tuts and its either been too confusing or somethings messed up, whatever but this is literally the first video that I've been able to follow start to finish and actually understood what I've done by the end of it. Big thank you for these videos, subbed my guy.
Much love brother 🤙
These comments keep me going ❤️🔥
This is one of the best and the latest please continue tutorial! Thank you Gadd Games!
Thank you very much the next episode will be out today or tomorrow but was delayed because I was recording the wrong screen 🤦♂️
I will cover jumping in the third video but if all you want is a simple character controller simply add a variable for jumpForce and in the update you can paste this code:
if(IsGrounded()&&Input.getKeyDown(KeyCode.Space)) velocity.y += jumpForce;
also set the jumpforce to be a serialized variable so yoiu can tweak it in game
Better than any tutorials i've seen! You're a legend!
Thank you very much brother I am working on episode 17 as we speak
Brilliant, there is no tutorial like this one.
All thins are well explained.
I'm following your tutorial for my open world game ! Excellent job -Thanks for segregation into chapters.
8:00 Just want to add, I've heard it's not good practice to have multiple CharacterController.Move calls in a single update loop as it could potentially cause some instability issues (plus it's really easy to fix). So my solution is to remove the move call from GetDirectionAndMove and Gravity, the in the Update loop after both those methods are called, create a Vector3 finalMove which is the sum of dir * moveSpeed and velocity, then call controller.Move(finalMove * Time.deltaTime)
Really enjoyed this first video, definitely would like this to flesh out into an entire series for a in depth Third Person Shooter Character. Subbed
Thank you, episode 5 will be out later today and a lot of people seem to be enjoying it so I will be continuing to add things like enemy AI and a full gameplay loop by the end.
You the best man explaining every single things
should continue this to another playlist .. very good content thank you , big help !
turn on the bell new videos coming soon, also I will be dropping the custom wheel collider and car controller asset for free and at some point will be adding cars to the project
Hey, Really helpful video. Quick question, how would i disable mouse acceleration? it seems to be activated.
Thanks your tutorials are the best
Thank you 🙏
Great tutorial man
im getting the error ArgumentException: Input Axis vertical is not setup and also the error:NullreferenceException: object reference not set to an instance of an object movementstatemanager.OnDrawGizmos() how do you fix these?? also this is for the movementstatemanager script
The camera part didn't work until I moved the main cam in the camera follow
Super beginner question but how does he actually make it move was there a separate video for bindings? Is it with a controller or keyboard am lost honestly
So Unity has basic inputs pre set up so the Horizontal and Vertical axis for the keyboard and mouse are there for you to use and change as you wish. hope this answers your question :)
Thank you I am just starting
oh my oh my! a new channel about Unity! Goodie!! thank you for the videos. Subscribe!!
Thank you 🙏
About the MovementStateManager, what software are you using for the scripting because for me it brought me to MS Word
Microsoft Visual Studio
I am using visual studio 2022 currently I believe in this video it was the 2019 version but either will work but id recommend 2022 as it is the latest
Do you have an updated AimStateManager Script for newer Cinemachine updates? I've been loving this tutorial but running into some issues particularly with the Axis. I put in the script you have (With changes "using Unity.Cinemachine;" instead of "using Cinemachine;) but AxisState is deprecated. I tried changing AxisState to InputAxis and get some errors I cant seem to get around. If I try to continue using the script as is, it still runs but when I run the game where you are at 14:08, x axis seems to work fine and the camera follows the mouse left to right but y axis doesnt seem to be registering. no up and down camera movement with all the same scripts as the vid. Are there any updates/fixes for this stuff? Thanks.
Can you help solve this error ? i dont know why but no error with 'Walk' and 'Crouch' and i stuck here.
Error:
\States\IdleState.cs(16,79): error CS1061: 'MovementStateManager' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'MovementStateManager' could be found (are you missing a using directive or an assembly reference?)
Make sure the variable or the RunState Class in the movement state manager is of type MovementBaseState. It seems like you may have it as a MovementStateManager class
@@gaddgames Omg, it's my fault while coding, i typed "public RunState Rn"
Hi, i followed all the instructions but i think is the new input system. Look when i put everything and go to check i have a problem that says : Cannot modify the return value of 'Transform.position' because it is not a variable
Please i need help. :(
You need transform with a lower case t
i love this man holy
Looks great. I plan to follow this tutorial but make a movable character for unity mobile (Coz I don't want to follow some tutorial deto copy and want to do some of the stuff myself. That's why choosing a different platform). Any advice you wanna give before I start following this series?
I did everything right but for some reason, I can't move my camera around whenever im moving the player but the player does move in the camera forward. How do i fix this
Do you still need any help brother?
@@gaddgames guess he doesnt need any help now
tip, use GetAxisRaw for a more responsive movement
Incrível esse tutorial, funcionou de primeiro mesmo tendo o básico em inglês foi o melhor tutorial de todos, continue assim, está de parabéns
Merci beaucoup monsieur!
What application did you use for the movement state manager? I can't open it because I don't have a compatible app
I use visual studio 2022 at the moment sorry for the late response, keep it up buddy
can help me fix the issue that when evry time i click play its says compile errors need to be fixed or something anyways great tutorial!
Great job
Thank u
Crazy beginner question. I'm starting with this video and Googling loads at every step. After creating the Movement State Manager script your screen goes to the place you can type code. What coding program is that?
Scratch that, I figured it out from another TH-cam video. But I'll keep the comment for the algo, if that helps? Thanks for the content!
@@MartyinVirtualReality Incase anyone else doesn't know its Microsoft visual studio.
Why would u do gravity inside the player object? Seems not scalable, the engine got its own way of dealing with this.
no matter what ı do it drops so fast what do ı do ?
Have specific option? I use alot of camera but I need just one to aim camera other just Free look
Hi, when i typed vInput, it sayed "the name vInput does not exist in current context can anyone help me?
Thank you so much bro!
Happy to help!
Whenever I add the ground layer and set the layer mask to it, my capsule still snaps/falls really fast. Has anyone else had this issue? Im on a slightly newer version of unity 2022.3.8
Tell me where I could have messed up, everything works for me, only the inversion on the y axis, when I move the mouse up, the character looks down and vice versa
here in this if we want that camera is alwys in d back side of character and follows character when on swipe we change camera angle than character angle must be same as camera...how this possible?
Outstanding!
Glad you like it!
Bro Great Video thank you so much,
How did you get a deep knowledge of c#, and do you have a Discord?
If I used someone else character controller script then what do I need to change to follow along with your next tutorials?
very cool. easy to follow.
Kool TPS Controller Could I use for commercial use?
Sure thing I quit my job yesterday so even more episodes coming soon
nothing is happening when I move my mouse around pls help
Have you fixed this issue yet? If not send me a message on discord
@@gaddgames I ended up with a brackeys video...dunno how but a code line solved it apparently lol
Is there a way to make the character rotate only after the camera reaches a certain angle? Trying to recreate Transformers fall of cybertron controls or like Minecraft 3rd person where your player rotates after a certain point
Thanks u, my bro!!!!
Thank you too!
Great tutorial!
Use some compression/limiting for your audio. You are very quiet!
please help me I keep on getting an error saying that the variable controller for movement state manager has not been assigned. I'm a beginner and I don't know how to solve this on my own and it wont let me play the game until I fix it. Please help!!!
i keep getting the error Assets\MovementStateManager.cs(8,6): error CS0246: The type or namespace name 'hideinspectorAttribute' could not be found (are you missing a using directive or an assembly reference?) what to do?
i typed in everything that was given to me and i keep getting the same 3 errors. someone please help😭
edit; nvm i was able to get rid of them but got a new one. error cs0103L the name 'controller' does not exist in the current conect
when should i do?
my mouse working opposite when i drag up camera faces down and vice versa any solution ??
Make sure you invert the input by putting a - behind where you capture the vertical input from the mouse
I followed your code for the Cinemachine, but it didn't pop up with the menu it did for you?
In the next video the axis states get replaced anyway lol
This guy is so smart
My friends would disagree :D
Anyone know how to controlee the CM virtual camera here with input from actionMap of new input system?
Have you found out how? I'm not sure how to, and I need help.
the camera always stays in the center of the screen it doesn't follow the player the code is correct i don't know why it doesn't work
Bro I'm unable to use Mouse X and Y. I did every step that you did but it dont work. please if you have any idea what i could do pleaaaasee say it to me. thanks
Watch the second video it gets changed anyway
@@gaddgames thanks mate
Thank you!!
i keep on getting errors that say Assets\MovementStateManager.cs(7,29): error CS1519: Invalid token '=' in class, record, struct, or interface member declaration
It can be you unity version
@@Thatonegamers11459 oh ok thanks I gave up like a year ago but that could be a good tip
@@Thatonegamers11459 so I’ll try again
@@Davidgotbored 🤣🤣 sorry
The code doesnt work for me (movement)
look if you did a type
You don't even have to make a ground check. The Unity CharacterController has it's build in controller.isGrounded. You can just check that with an if statement and handle the rest of the logic in there.
I didn’t know this but I did it the way I did it to make sure you can’t infinite jump up walls
Gadd Games are you planning to create your own discord server?
Discord link is somewhere on my TH-cam banner
don't you have tutorial just like this series where you use the new input system?
I’m tempted to make a video on how to upgrade this project to the new Input system. But will probably continue the series with the old system due to simplicity
create fps multiplayer series tutorial using photon pun 2 and mixamo animations please!
Camera script doesn't work with Unity 6 at all, but good tutorial after all.
Thank you for reminding me I picked Unity back up after a few months break and saw they had a Unity 6 so I upgraded the project and realised the same thing so I will have to make a new video for the cinemachine update
@@gaddgames is there a new video for this i am losing my mind bc of this change unity made. Amazing work btw ty so much !!
everything works ok apart from the movement it doesn't go in proper direction
That was my mums favourite part of the video, in the future I am going to edit it less so I will show that I am no genius and it takes time, effort and persistence. I am still learning and always will be
Hey Gadd, I followed every step of this video exactly but the character doesn't stop moving for a few more seconds even after I took my hands off the controls.
Here's the code(If there's something that I did wrong, please tell me!):
MovementStateManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementStateManager : MonoBehaviour
{
public float movespeed = 3;
float hzInput, vInput;
[HideInInspector] public Vector3 dir;
CharacterController controller;
[SerializeField] float groundYOffset;
[SerializeField] LayerMask groundMask;
Vector3 spherePos;
[SerializeField] float gravity = -9.81f;
Vector3 velocity;
void Start()
{
controller = GetComponent();
}
void Update()
{
GetDirectionAndMove();
Gravity();
}
void GetDirectionAndMove()
{
hzInput = Input.GetAxis("Horizontal");
vInput = Input.GetAxis("Vertical");
dir = transform.forward * vInput + transform.right * hzInput;
controller.Move(dir.normalized * movespeed * Time.deltaTime);
}
bool IsGrounded()
{
spherePos = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
if (Physics.CheckSphere(spherePos, controller.radius - 0.05f, groundMask)) return true;
return false;
}
void Gravity()
{
if (!IsGrounded()) velocity.y += gravity * Time.deltaTime;
else if (velocity.y < 0) velocity.y = -2;
controller.Move(velocity * Time.deltaTime);
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(spherePos, controller.radius - 0.05f);
}
}
anneyong, try this bro:
public class MovementStateManager : MonoBehaviour
{
#region Movement
public float currentMoveSpeed;
public float walkSpeed = 1, walkBackSpeed = 1;
public float runSpeed = 3, runBackSpeed = 3;
public float crouchSpeed = 2, crouchBackSpeed = 1;
[HideInInspector] public Vector3 dir;
[HideInInspector] public float hzInput, vInput;
CharacterController controller;
#endregion
[SerializeField]float groundYOffset;
[SerializeField] LayerMask groundMask;
Vector3 spherePos;
[SerializeField] float gravity = -9.81f;
Vector3 velocity;
MovementBaseState currentState;
public IdleState Idle = new IdleState();
public WalkState Walk = new WalkState();
public CrouchState Crouch = new CrouchState();
public RunState Run = new RunState();
[HideInInspector] public Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponentInChildren();
controller = GetComponent();
SwitchState(Idle);
}
// Update is called once per frame
void Update()
{
GetDirectionAndMove();
Gravity();
anim.SetFloat("hzInput", hzInput);
anim.SetFloat("vInput", vInput);
currentState.UpdateState(this);
}
public void SwitchState(MovementBaseState state)
{
currentState = state;
currentState.EnterState(this);
}
void GetDirectionAndMove()
{
hzInput = Input.GetAxis("Horizontal");
vInput = Input.GetAxis("Vertical");
dir = transform.forward * vInput + transform.right * hzInput;
controller.Move(dir.normalized * currentMoveSpeed * Time.deltaTime);
}
bool IsGrounded()
{
spherePos = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
if (Physics.CheckSphere(spherePos, controller.radius - 0.05f, groundMask)) return true;
return false;
}
void Gravity()
{
if(!IsGrounded()) velocity.y += gravity * Time.deltaTime;
else if (velocity.y < 0) velocity.y = -2;
controller.Move(velocity * Time.deltaTime);
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(spherePos, controller.radius - 0.05f);
}
}
@@Dominicn123 Thanks for the help! I really appreciate it!
I HAVE A 22 COMPILLER ERRORS🤧🤧🤧
Can someone sent a working code pls?
Yet another tutorial that doesn't work (probably due to Unity's constant annoying updates). It wouldn't let me add a CineMachine Virtual Camera unless I parented it to an object on the hierarchy and it's symbol doesn't appear next to the main camera and it doesn't function. I'm so sick of unity's bullcrap.
I’ll have a look into it and see if I can find a fix for you
@@gaddgames Never Mind, I got it to work! For some reason, if I selected it in the Component Tab from the tab, it would be grayed out and not selectable unless I parented it to an object in the hierarchy, in which case it wouldn't work. However, when I right-clicked the Hierarchy and selected Cinemachine and virtual camera from there, it worked just as you showed. Thank you for your attempted support regardless!
why the MonoBehaviour is white and not blue? same for other things they are white not grey
asking bc the script isnt working without these
If you go on Unity and click file/project settings/ external tools. Do you have your IDE selected in the drop down?
@@gaddgames wait unity hub or the project?
@@Gli_sck when your in the project. If you still need help send me a message on discord and I can help you get it sorted
@@gaddgames oh i discovered how to fix that, thanks for replying you're a very good youtuber:)
i got some error that said:
nullreferenceException: object reference not set to an instance of an object movementStateManager.OnDrawGizmos
can someone help me
Run the game and it will go away and when you have set it up just comment out the code and it will go away
hide in inspector not visible help me sir
Does this tutorial work for FPS game?
It tells '*' cannot be used for vector3
In the first script
Theres something wrog with my code please help ive reviewed it so many times
me too
public float moveSpeed = 3f;
[HideInInspector] public Vector3 dir;
float hzInput, vInput;
CharacterController controller;
[SerializedField] float groundYOffset;
[SerializedField] LayerMask groundMask;
Vector3 spherePos;
[SerializedField] float gravity =-9.81f;
Vector3 velocity;
only moveSpeed is showing in inspector. why?????
Serialize instead of Serialized
Go to file at the top left of Unity then preferences/ external tools, then select your IDE from the drop down menu then regenerate project files then it should make things easier to follow along with
@@gaddgames oh shit. lmfao thank you. Can't believe I did that. its My intellisense that seems to be screwing me over and I didn't look properly
@@gaddgames I did that now. its not that. there is something wrong with the assemblies not showing up for me for some reason. I had a fix for it but that doesn't seem to be an option for me sadly. do you have a discord?
Yeah there is a link to it on my channel banner thing
I am 117th comment...
MISTER CHEF
how does one add jumping
By carry on watching the series
What do you use for the code?
vs code
I’m using visual studio 2022 in this video
hello im becoming an indie developer is it possible to change the model with my own?
Yes you can in the second episode which is out now I show you how to replace the model with the capsule and get the animations set up. Finally in the third episode I will be showing you how to write the code to change the animations depending if you are running, crouching or walking. If you have any questions feel free to message me on my discord which you can find on my website gadd.games
The discord link is in my links page on my website also make sure to read the pinned comments on this video. Thank you for watching!
cant get the jumping workinng
king king u are a king amk !!!!!!
I'm but a mere peasant good sir
is this series suitable for beginners
I wouldn’t recommend for absolute beginners but definitely with a basic knowledge of unity you could follow along
@@gaddgames iam a absolute beginner which series shopuld i watch for unity (other than brackeys )i like to learn 3d stuff not 2d games
What I did to start learning was the create with code course on the Unity learn website was very helpful and simple to understand
i dont know if it is just me but rotation is very laggy
Thanks for the tutorial, btw, i use rigidbody, so i can't follow 3/4 of the tutorial :(
Might have to make a rigid body movement tutorial 🤔
Aus spaß macht sowas keiner kein verbrechen ohne das man was verdient !
What language is he using
C#
Why do you not use rigibody??
why does unity take fucking forever to do anything
kam ni kitta :(
何が問題ですか
When im testing
AimStateManager:
using UnityEngine;
using Unity.Cinemachine;
using UnityEngine.InputSystem;
public class AimStateManager : MonoBehaviour
{
[SerializeField] private Transform camFollowPos;
[SerializeField] private float mouseSensitivity = 1f;
private float xRotation;
private float yRotation;
private PlayerInput playerInput;
private InputAction lookAction;
private void Start()
{
// Set up input
playerInput = GetComponent();
if (playerInput != null)
{
lookAction = playerInput.actions["Look"];
lookAction?.Enable();
}
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void OnDisable()
{
lookAction?.Disable();
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
private void Update()
{
if (lookAction != null)
{
// Get input from new Input System
Vector2 lookDelta = lookAction.ReadValue();
// Apply sensitivity
xRotation += lookDelta.x * mouseSensitivity;
yRotation -= lookDelta.y * mouseSensitivity;
// Clamp vertical rotation
yRotation = Mathf.Clamp(yRotation, -80f, 80f);
}
}
private void LateUpdate()
{
if (camFollowPos != null)
{
// Apply rotations
camFollowPos.localEulerAngles = new Vector3(yRotation, camFollowPos.localEulerAngles.y, camFollowPos.localEulerAngles.z);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, xRotation, transform.eulerAngles.z);
}
}
}
---------------------------------------------------------------------------------------------------------------
MovementStateManager:
using UnityEngine;
public class MovementStateManager : MonoBehaviour
{
[SerializeField] private float moveSpeed = 3f;
[SerializeField] private float groundYOffset = 0.1f;
[SerializeField] private LayerMask groundMask;
[SerializeField] private float gravity = -9.81f;
private CharacterController controller;
private Vector3 velocity;
private Vector3 movementDirection;
private Vector3 spherePosition;
private void Awake()
{
// Cache the CharacterController component for performance
controller = GetComponent();
if (controller == null)
{
Debug.LogError("CharacterController component is missing!");
enabled = false;
return;
}
}
private void Update()
{
// Calculate movement direction
GetDirection();
// Apply gravity
ApplyGravity();
// Combine movement and gravity, then move the character
Vector3 finalMove = movementDirection * moveSpeed + velocity;
controller.Move(finalMove * Time.deltaTime);
}
private void GetDirection()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
movementDirection = transform.forward * verticalInput + transform.right * horizontalInput;
}
private bool IsGrounded()
{
spherePosition = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
return Physics.CheckSphere(spherePosition, controller.radius - 0.05f, groundMask);
}
private void ApplyGravity()
{
if (IsGrounded())
{
// Reset gravity when grounded
if (velocity.y < 0)
{
velocity.y = -2f; // Slight negative value to ensure contact with the ground
}
}
else
{
// Apply gravity over time when not grounded
velocity.y += gravity * Time.deltaTime;
}
}
private void OnDrawGizmos()
{
// Visualize the ground check sphere in the Scene view
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(
new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z),
controller != null ? controller.radius - 0.05f : 0.5f
);
}
}
6 Jahre Bau wenn du in ein fremdes netzwerkt eindringst !! :)
This video is not for beginner
My character is not moving
I dont understand why ur voice is low please before making any tutorial at least check your sound
NullReferenceException: Object reference not set to an instance of an object
MovementStateManagement.OnDrawGizmos () (at Assets/MovementStateManagement.cs:60)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) i have this problem how i can fix
did you get this fixed? pls help a fellow out if so
ay man im stuck at 14:00 i cant play bc it automaticly pauses the game and when i try to unpause it gives me an error saying: System.ArgumentException: Input Axis Mouse Y is not setup. can you help me out please?
nwm did it myself lol
@Kapsuva81165 good job 😁