First Person Character Controller - FPS Game With Unity & Blender
Вставка
- Опубліковано 7 жов 2024
- FIRST PERSON CHARACTER CONTROLLER
In the sixth episode of the FPS Game remake I show you how to make a first person character controller that can walk, run, jump and fall. If you want me to add crouching feel free to let me know in the comments.
Feel free to donate if you are rich :D
streamlabs.com...
Thanks to: Robin Brown, Tom Taborovski and Samin Grahic for their support on Patreon.
Discord Server - / discord
Patreon - / singlesapling
Twitter - / singlesaplingg
Reddit - / singlesaplinggames
Instagram - www.instagram....
DeviantArt - singlesaplingg...
Facebook - / single-sapling-games-2...
Itch.IO - single-sapling...+
Tumblr - / singlesapling
UA-cam - / @singlesapling
--Programs--
Engine: Unity - unity3d.com/
Modeling: Blender - www.blender.org/
2D Editing: Krita - krita.org/en/
Programing: Visual Studio - visualstudio.m...
Organization: Trello - trello.com/
--Outro Music--
Song: Horizon (feat. Tylah Rose) - Loreno Mayer & Haesën
Music provided by Ninety9Lives
Video: • Loreno Mayer & Haesën ...
Download: 99l.tv/88HorizonYU
--TAGS--
script make game for free 2020 development dev unity blender program tutorial guide new hd twitter youtube developer indie design art cool easy quick fast fps first person shooter game gaming how to intro introduction learn teach learning teaching livestream live stream indiegamedev indiegame indie unity2020 blender3d unity3d devlog
Problem: Player can jump multiple times
Solution: He forgot to set the layer mask when setting isCharacterGrounded. Here is how to fix it. At 24:34 he makes this line:
isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);
He forgets at the end of the line after groundDistance to specify which layer it should check. This is why you jump so much. To fix it you simply use the already made LayerMask called groundMask. So the line should go from the above to the following:
isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);
Hope this helped!
Yeah
Thanks so much!!! i had trouble reading so i might add extra lines to make it cleaner.
how to fix:
find "isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);" in "HandleIsGrounded"
around line 60.
then add "groundMask" after "groundDistance" so it should end up looking like this:
isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);
Thank you man
@@mahoromatic02 No problem. Merry christmas
thx helped alot
If every Unity tutorial was as good as yours, we'd all be working at Nintendo. Great job, man! Keep up the good work! 👍 The way you explain things, the encouragement you provide, and the coding practices you teach... I believe you can become the new Brackeys!
Aw sheeet, thanks man
Out of all the tutorials my stupid ass has watched, single sapling has the ones that I struggle with the least, I don't run into as many errors and bugs with his stuff. I can't wait to get deep into making my game, I especially can't wait to learn how to do proceederal generation, that will be fun, but probably also a nightmare
Very good tutorial! Maybe you can create tutorial series like that but 3rd person? Please?
I just want to say the organization method you use is super helpful! I have never seen anybody on UA-cam use this but I'm glad you showed me
Because it actually helps me remember what every bit of code does since the voids names tell me what they do
So this is super helpful for noobs like me
These tutorials are amazing!!! Been wanting to get a start on modeling and game design once I get a break from college in the summer and this is the time. Glad I found these, this is everything I could've asked for and more. Very comprehensive and to the point, making sure to explain anything that may be ambiguous so that we can actually learn instead of just following a step by step process where we don't actually learn anything. Thank you so much for these tutorials. I have your blender shortcuts tacked on my wall above my monitor and its really nice to have. It's very nice of you to offer all of this for free, and believe me when I say that they will always be appreciated (even 9 months after posting).
I am a beginner to unity with little to some xperience, and this has helped me learn a lot about variables, vector3, floats, and so many more things. thank you so much for everything
*This is a really good guide btw*
I've noticed, and I'm not the only one, that you can jump multiple times using these scripts.
A solution (props to @Vangsguard) is to add 'groundMask' at the end of your code.
Example:
(skipped out a bit of code, but you could find the code in your code)
private float groundDistance;
private LayerMask groundMask;
private void HandleIsGrounded()
{
isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);
}
(For this, add ', groundMask' to the end of the code in the brackets so that it looks like: isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);)
Additionally, make sure to make the layer of any ground you have set to the same layer mask (in my case, groundMask)
(Single Sapling goes over that in his video)
Afterwards, you may encounter a problem that you can't jump whatsoever. However, your gravity has been made more realistic if you start at a high y level.
A fix to this is to go into the game preview and change the 'groundDistance' variable in your inspector until the 'isCharacterGrounded' bool variable is ticked.
If it is not ticked, you won't be able to jump.
(IDK why this happens, as I am fairly new, but it works so eh, some programming nerd could explain it)
Now the gravity and jumps are both realistic.
Hope this helps someone, and if you need help, just comment on this / tag me, and I will try to respond.
:)
Thanks! You helped me out!
Thank you!! I changed the 'groundDistance' to 1.1 greater than my players y axis position (my case y = 1.08) after playing.
One of the best Unity tutorial! Nice job
:*
the only tutorials ive found that actually explain what the code is doing and how its doing it, all the others are "just write this and it does this" instead of actually explaining things
:}
so far i've been learning a lot from your videos man thank you !!! 😍👍❤❤
you're a great teacher, thank you for this tutorial
very good tutorial!
good job!
Great Video but wouldn't it be a good idea to use the new Input system or is it not up to sctrach? I have been trying to find a good first-person character tutorial for it for a while
Yeah, Ive been looking for some good documentation for it so I am not using it yet, but hopefully soon
Top
15:42 marking my point
as soon as i finished the jumping code, my player just keeps flying up?!?!
with the player movement can you make the camera like bob and offset when you land from jumping or falling
You forgot groundMask in Physics.CheckSphere
My isGrounded code does not check if my character is grounded
Since I can still jump in the after putting it in the if statement of handle jumping
Edit: okay fixed it, the solution was to add the ground mask variable to the handle is grounded code
Check everything in the video again, really check it and then let me know if its still there
@@SingleSapling the code is a bit quirky it seems but if I add the ground mask variable to the handle is grounded code
Like so
IsCharacterGroundrd = Physics.CheckSphere(transform.position, ground distance, GroundMask);
Then it works
So
Yay :D
my players feet dont touch the ground because when i put the arms pivot everything goes up not just the arms pivot so when i do the code to stop jumping infinitely it doesnt work because the feet are at the arms pivot and therefore never actually touches the ground. (Idk if this makes sense but all im saying is when u clikc on player it is on the ground but when i click player it is at my arms)
Any idea why my player doesn't want to move?
At one point on my plane I start to fall through the plane. Any solutions?
need help with the draging the first script part, its crashing my unity editor/unityhub
Crashing?!
Where do you get this information from?
When i drag the arm model into the empty arms object, the player position gets moved to 1.65m. Cant find a way around this
Try again
Why do you make variables serialize field when you can make them public
I explained at one point, serialize field is literally made for this use so...
@@SingleSapling but you can make it public
@@SingleSapling why use serialize field
Sure you could, but this makes is so its not accesible by other scripts, it keeps the code clean and its just good practice all around
@@prabhnoorsingh8235 What i understood is that its a good way of protecting scripts. Like when people exploit so you cant access it from other scripts or change it. Thats why its private, and he add SerializeField to still be able to change the variables in the editor. Hope this explained why :D
i found a better way to implement the sprinting with smooth transition you just have to make another variable name it accelaration (or whatever)
and change the two if functions with this
if(Input.GetKey(KeyCode.LeftShift))
{
moveSpeed = Mathf.Lerp(moveSpeed, Runspeed, Sprint_Acceleration * Time.deltaTime);
}else{
moveSpeed = Mathf.Lerp(moveSpeed, Walkspeed, Sprint_Acceleration * Time.deltaTime);
}
Nice
i haver a problem. when i add groundMask i cant jump but when i remove it i can infinite jump. Any solutions?
In the inspector, does the isGrounded variable in the script change at all?
why do the feet go to my arms when i add them into the hierarchy?
First time hearing that
The feet pivot is moving in I add the low poly arms :c
I have the same problem, any solutions?
If anyone in the future has the same problem, this was Single Saplings anwer that worked for me:
Does changing the transform point from Center to Pivot help? In the top left, right next to the tools
@@HumanDoing nice I'll try it
Can I use Rigidbody for fps controller
U can but that is significantly harder to do
quick tip: for running you could just use moveSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed
Indeed that would be much cleaner. This tutorial obviously isnt for you my man you too smart, this is for beginners