Player Script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class player : MonoBehaviour { public Animator playerAnim; public Rigidbody playerRigid; public float w_speed, wb_speed, olw_speed, rn_speed, ro_speed; public bool walking; public Transform playerTrans;
I keep getting "Can't add script component 'Player' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.".
At 10:53 in the video when discussing the sprinting, I use "=!" As an "equal to" symbol when in reverse it actually means "doesn't equal to", I should've used "==", just wanted to correct myself there lol. This mistake has nothing to do with the code, just the text in the video I was using to explain what to do.
i have a question, when i press W or S my player run forward or backwards and thats good but when i release one of that keys my camera and player dont stop but keeps going forward or backwards in idle modus. Can you help me?
my character is not stopping. Please tell me the solution for this and also my character in moving on plane surface but on terrain (i mean on little bit distorted surface ) it is not walking properly
Hi! I implemented this in my own game but the character's collision with the terrain isn't working too good. Sometimes it gets stuck in it if it's trying to go upwards, then when i got down, it floats. What can I do to fix this?
Hey, can you please tell me about how to add an animation that plays when you press a or d? I have set up the a and d movement and a different camera movement style, and I have a trigger for the animation in the controller, but when I reset Idle in the script and set the sideways animation it just does a tpose. I even connected the sideways animation with every other animation in the controller, please help!
Hey, from where can I find as same as you character "Master Chief" ? Because When I download a character from mixamo then I uploaded again, I could not make my own rigging?! like what you did at 1:28.
Does your character still move it's just off the ground? If that's the case then I recommend editing your capsule collider. In the component it should say edit. Press that and edit where his feet are and make it smaller
Great Vid! But I have a problem with the animations.. when I walk and stop it has to finish the animation and when I keep walking it teleport the character behind me. So it player stops moving but the animation still goes. Anyone know what is happening?
I keep getting "Can't add script component 'Player' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." when I put in the code.
for me i never installed a character to use but rather the character and animation from mixamo, and now i don't know if i am supposed to restart with a character i downloaded
Great video the animations work, but one problem. If I turn my character it will still go in the Z axis, is there a way I can fix this? Is there some part in the video I'm missing?
Thanks for the tutorial! I have a question though. Why is it necessary to make the model a child of the capsule? Isn't it just possible to delete the capsule and it is done? :D
im having a problem for lines 71 72 73 and line 1 saying that A using clause must precede all other elements defined in the namespace except extern alias declarations yall know how to fix
help please! I keep getting these errors: Assets\player.cs(70,1): error CS8803: Top-level statements must precede namespace and type declarations. Assets\player.cs(70,14): error CS1002: ; expected Assets\player.cs(71,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations Assets\player.cs(72,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations Assets\player.cs(73,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations Assets\player.cs(70,14): error CS1022: Type or namespace definition, or end-of-file expected
hey! how r u? well... my the animations are working so perfect but, my character don't move forward or backward, just for the left or the right. how can i fix it?
Hi, I have made my terrain to be in even like going up and down a hill, my character is not staying on the ground, it starts on it but as soon as the terrain is uneven the character floats. Can you please help me
12:26, mines still buggy, dosnt go back also the animation gets stuck sometimes character also dosnt turn the walk speed also sometimes increases twice when i press shift, like for example, i press shift and stop wlaking, i do it again and the speed is240, again and its like 400 also, initially the walk speed and walk back speed is really slow and seems like its not moving edit: it seems ive fixed the turning but not the speed problem
Player Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
public Animator playerAnim;
public Rigidbody playerRigid;
public float w_speed, wb_speed, olw_speed, rn_speed, ro_speed;
public bool walking;
public Transform playerTrans;
void FixedUpdate(){
if(Input.GetKey(KeyCode.W)){
playerRigid.velocity = transform.forward * w_speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.S)){
playerRigid.velocity = -transform.forward * wb_speed * Time.deltaTime;
}
}
void Update(){
if(Input.GetKeyDown(KeyCode.W)){
playerAnim.SetTrigger("walk");
playerAnim.ResetTrigger("idle");
walking = true;
//steps1.SetActive(true);
}
if(Input.GetKeyUp(KeyCode.W)){
playerAnim.ResetTrigger("walk");
playerAnim.SetTrigger("idle");
walking = false;
//steps1.SetActive(false);
}
if(Input.GetKeyDown(KeyCode.S)){
playerAnim.SetTrigger("walkback");
playerAnim.ResetTrigger("idle");
//steps1.SetActive(true);
}
if(Input.GetKeyUp(KeyCode.S)){
playerAnim.ResetTrigger("walkback");
playerAnim.SetTrigger("idle");
//steps1.SetActive(false);
}
if(Input.GetKey(KeyCode.A)){
playerTrans.Rotate(0, -ro_speed * Time.deltaTime, 0);
}
if(Input.GetKey(KeyCode.D)){
playerTrans.Rotate(0, ro_speed * Time.deltaTime, 0);
}
if(walking == true){
if(Input.GetKeyDown(KeyCode.LeftShift)){
//steps1.SetActive(false);
//steps2.SetActive(true);
w_speed = w_speed + rn_speed;
playerAnim.SetTrigger("run");
playerAnim.ResetTrigger("walk");
}
if(Input.GetKeyUp(KeyCode.LeftShift)){
//steps1.SetActive(true);
//steps2.SetActive(false);
w_speed = olw_speed;
playerAnim.ResetTrigger("run");
playerAnim.SetTrigger("walk");
}
}
}
}
Camera Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camLookat : MonoBehaviour
{
public Transform player, cameraTrans;
void Update(){
cameraTrans.LookAt(player);
}
}
I keep getting "Can't add script component 'Player' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.".
@@NutshackVideos check if your public class name is same as script name
@@tofue9506 Actually, I got the problem solved. Thanks!
@@NutshackVideos how did you do, i got similars errors.
I have a problem where my character just slides when I stop moving, could you help?
I just started leaning Unity and I did understand everything. Thanxxx
same, good job
Good straightforward tutorial man. THank goodness. Also uploading the script in a comment like a champ!
At 10:53 in the video when discussing the sprinting, I use "=!" As an "equal to" symbol when in reverse it actually means "doesn't equal to", I should've used "==", just wanted to correct myself there lol. This mistake has nothing to do with the code, just the text in the video I was using to explain what to do.
that's what I kind of assumed but its thoughtful of you to clarify.
Thank you so much! This helped me a lot in my unity 3d gamejam project
Thanks to you I succeeded to animate and control my Character🙂
Glad the tutorial could help :)
@@Omogonix Your video is the best tutorial and the clearest, and the easiest
@@Omogonix hello can someone help me when i pres w to walk my player keep walking how to fix this?
Just made my first 3d animated character thanks to this video, there are some improvements to make but this will do for now.
hello can someone help me when i pres w to walk my player keep walking how to fix this?
@@DIBRA07-F same problem
Can you please make an updated version with jump and non tank controls plz i cant figure it out
Man, I really appreciate the time and effort you put into this video. I can't thank you enough for what you did.
Hated the cinemachine Controller, It was weird. Thanks for your tutorial
If your Character is floating, decerase your capsule height from Capsule Collider section.
thanks! problem solved
Cheers for the tutorial, although the music in the last 5 minutes made me feel like I was doing a GTA heist
Hahaha! That made me laugh
very useful
i have a question, when i press W or S my player run forward or backwards and thats good but when i release one of that keys my camera and player dont stop but keeps going forward or backwards in idle modus. Can you help me?
same problem, did you fix?
In this case you need to make sure you also put if function for release of W and S button and in that function put all vector3 parameters 0
Try to make Rigidbody-Drag to 10
Youre a life saver
can you please do a tutorial for a character from unity asset store??
Thanks bro love from India 🤗🤗
Thanks SO MUCH😍😍♥
Thank you very much for your tutorial with which I learned better about animations in Unity.
Really good Video!
Thanks!
Nice. Apart from my character doesn't collide with anything.
best last time Music Sound.
Amazing work!
This was the most helpful video I ever watch🤩, Thank you so much!
subbed ❤😇
I know I am late, but I think making a halo fan game would be something really 👍
Any ideas on how to rotate the camera? With the mouse?
The animations make it so he only runs on the spot and is stay still, instead of running the whole thing. How do I fix please?
very usefull video thx!!!
Thanks :)
Please, i need much help, I did everything like the video, but my character continues walking when I stop pressing W
my character is not stopping. Please tell me the solution for this and also my character in moving on plane surface but on terrain (i mean on little bit distorted surface ) it is not walking properly
pull the capsule up and and the leg of your model must be visible it can fix your problem
set drag to 10
and how l change the entry to idle animation??
Amazing Tutorial, one problem though: Unity gives errors about the unchecked Exit Time, so the transition is ignored. How do i fix this?
at the bottom where it says condition set it to the animation you are going into, like when it goes from idle to jog set the condition as jog
Hi! I implemented this in my own game but the character's collision with the terrain isn't working too good. Sometimes it gets stuck in it if it's trying to go upwards, then when i got down, it floats. What can I do to fix this?
change the capsules collider a bit
If your Character is floating, decerase your capsule height from Capsule Collider section.
Hey, can you please tell me about how to add an animation that plays when you press a or d? I have set up the a and d movement and a different camera movement style, and I have a trigger for the animation in the controller, but when I reset Idle in the script and set the sideways animation it just does a tpose. I even connected the sideways animation with every other animation in the controller, please help!
Instead if trigger make it bool
hello can someone help me when i pres w to walk my player keep walking how to fix this?
Nice
thank god
i just have a problem, The animations work perfect but my character isnt actually moving at all
Hey, from where can I find as same as you character "Master Chief" ?
Because When I download a character from mixamo then I uploaded again, I could not make my own rigging?!
like what you did at 1:28.
why do i get this error i dont know how to fix it:
Assets\player.cs(1,14): error CS1022: Type or namespace definition, or end-of-file expected
Same here, we need help
@@josephreubenfab ye
did you fix it?
@@greennlvr
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public Animator playerAnim;
public Rigidbody playerRigid;
public float w_speed, wb_speed, olw_speed, rn_speed, ro_speed;
public bool walking;
public Transform playerTrans;
void FixedUpdate()
{
if (Input.GetKey(KeyCode.W))
{
playerRigid.velocity = transform.forward * w_speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
playerRigid.velocity = -transform.forward * wb_speed * Time.deltaTime;
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
playerAnim.SetTrigger("walk");
playerAnim.ResetTrigger("idle");
walking = true;
}
if (Input.GetKeyUp(KeyCode.W))
{
playerAnim.ResetTrigger("walk");
playerAnim.SetTrigger("idle");
walking = false;
}
if (Input.GetKeyDown(KeyCode.S))
{
playerAnim.SetTrigger("walkback");
playerAnim.ResetTrigger("idle");
}
if (Input.GetKeyUp(KeyCode.S))
{
playerAnim.ResetTrigger("walkback");
playerAnim.SetTrigger("idle");
}
if (Input.GetKey(KeyCode.A))
{
playerTrans.Rotate(0, -ro_speed * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.D))
{
playerTrans.Rotate(0, ro_speed * Time.deltaTime, 0);
}
if (walking)
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
w_speed += rn_speed;
playerAnim.SetTrigger("run");
playerAnim.ResetTrigger("walk");
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
w_speed = olw_speed;
playerAnim.ResetTrigger("run");
playerAnim.SetTrigger("walk");
}
}
}
}
you had syntax problem, try this
Great vid, but when I move my character like teleports a step back. Any idea on how to fix this? thanks
You didn't check inplace when you download the animation from mixamo
Great video! I only have one issue, if I walk to far away, the camera teleports to the player and it looks a bit janky, any idea on how to fix this?
same please tell me the fix
sorry for the question, but how can i add animated jump? thank you.
Hi.
Can you add jump animation?
How to code WASD 3D character movement on UNEVEN TERRAIN?
Hello! Great tutorial. The animations are working but when I stop, for some weird reason, I just slide. Is there a way of fixing this? Thank you!!
Hi! Try setting the Rigidbody's Drag to 10
@@Omogonix It worked! Tysm.
Ty too
it doesnt work pls help
@@Omogonix
@@Omogonix thank you!
What do I do if half of my character's body is falling into the ground
Select your character
In inspector tab go to rigidbody component
Constraints-->freeze rotation and freeze x and z rotation
I have a problem, my character stays in the air while I am pressing the keys for move, I do not know how I can fix that please help :(
select the animations and use bake into pose
and select original
and apply
@@abhisek3735how make this???
Does your character still move it's just off the ground? If that's the case then I recommend editing your capsule collider. In the component it should say edit. Press that and edit where his feet are and make it smaller
Or checking the groundcheck is right make sure that you have gravity applied also
why in my player script, input for number speed is didnt exist in mine ?
tanks brother for the script
Great Vid! But I have a problem with the animations.. when I walk and stop it has to finish the animation and when I keep walking it teleport the character behind me. So it player stops moving but the animation still goes. Anyone know what is happening?
i have same problem
Can you hold on and climb? I like the video content
it kinda works my charecter is floating and the animations dont work. how to fix this?
If your Character is floating, decerase your capsule height from Capsule Collider section.
How to make Camera moving with mouse? (sorry for bad english)
I keep getting "Can't add script component 'Player' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." when I put in the code.
Hey it worked but the animation is shattering can you solve this. Its like someone pulling back like glitch of online games. Please help
for me i never installed a character to use but rather the character and animation from mixamo, and now i don't know if i am supposed to restart with a character i downloaded
I think i can code a first person camera and attach it to the player and combind it with ur script ill try
apologies, can I get additional source code to jump?
hi, I've been doing everything correctly but in my player script, the variable component doesn't show up. any idea why?
Great video the animations work, but one problem. If I turn my character it will still go in the Z axis, is there a way I can fix this? Is there some part in the video I'm missing?
Nevermind, I fixed the problem
@@tristkelly2710what did u do to fix it? I heard to increase the rigs drag to 10 idk.
@@MercyKOTG Just make sure the capsule is exactly matching with the capsule, If this doesn't work I may have another solution
here if we want that camera should be back side of character if character rotate than camera should also rotate...how to done that?
Thanks for the tutorial! I have a question though. Why is it necessary to make the model a child of the capsule? Isn't it just possible to delete the capsule and it is done? :D
The Capsule Is The Hitbox For The Player
Please tell me why my character's animation is quite good but only running in place. Please help me!
i keep getting trouble with the variables even tho i put the script in the player parent it dosent show me the properties to fill in the variables
make a tutorial how jump
Bro where is aninater tab in don't have
U can add it on window and then animator
Which version of you visual studio and unity
for some reason my character is not moving
im having a problem for lines 71 72 73 and line 1 saying that A using clause must precede all other elements defined in the namespace except extern alias declarations yall know how to fix
Unity says The referenced script on this Behaviour (Game Object 'Player') is missing!
i don't know what it means someone help me please
I have an issue, when I drag the script to the parent model it does not work, any help?
i have a little problem that is when i press the w or s key the player doesn't stop and does a sliding
set rigidbody drag to 10
help please! I keep getting these errors:
Assets\player.cs(70,1): error CS8803: Top-level statements must precede namespace and type declarations.
Assets\player.cs(70,14): error CS1002: ; expected
Assets\player.cs(71,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
Assets\player.cs(72,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
Assets\player.cs(73,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
Assets\player.cs(70,14): error CS1022: Type or namespace definition, or end-of-file expected
im having the same errors could you explain what you did to solve those
delete camera's script from the player's script. be careful when copying the code.
For Me, All it says in the player script is the tab that say player. How Can I Fix This?
The tutorial was great but I have a question my character is floating he can animate and can move but the gravity was not working? thank you.
try to dont enabled freeze position on rigidbody y
If your Character is floating, decerase your capsule height from Capsule Collider section.
want to ask, why my animation at the animator workspace still tposing?
please help me its been 3 hours and i my animations still dont work with every video on the internet please help
hey! how r u? well... my the animations are working so perfect but, my character don't move forward or backward, just for the left or the right. how can i fix it?
same
walk does my variables not pop up
For some odd reason, my character can't rotate. It moves forward or backward, but it can't change it's direction. Any help?
The Capsule called Player needs to be in the transform variable
My player will move forward and back but I cant turn
What about for jumping
My character keeps teleporting back while he's moving I can't figure out why
make sure when you download the animations you have the "in place" box ticked, I had the same problem and that fixed it
@@Glade2426 wdym in place? i have the same problem too can you explain plz
how to rotate with some position
How to download the character can you please inform
i have a problem my character is not walking and is just animating the walk forward and backwards and idk why because he is running
make sure to drag player to Player Rigid in the inspector
why in mine variable is not exist?
i added the script to the models parent and the variables didnt pop up
if i sprint while using w it eventually slides for a bit if i stop moving anyone have a fix for this?
When I hold the buttons to move, my character basically loops the animation and moves back a bit at every loop. Is there any way to fix this?
check the loop pose voice, it fixs the problem.
@@rosariocascone Nope he downloaded the animation without clicking inplace option🤣🤣🤣
@@beast0titan i personally clicked on in Place but It didn't worked, so i used this trick
@@beast0titan some animations in mixano, Like backjog, have a problem. I don't speak english very well so i can't explain, do you speak italian?
@@rosariocascone ok fine
i didnt got the animator thing near play button
hello I saw your video, only the void error FixedUpdate () comes out, what should I do?
Hey, what does the error say exactly?
@@Omogonixtells me this: the associated script can not be loaded. please fix amy compile errors and assign a valid script.
@@LordGeson What are the compile errors? Sorry for taking a while to reply
@@Omogonix do not worry indeed I must also thank you that you are answering me, can I contact you on discord so it's easier?
good tutorial but how to color the charater ?
with textures, just drags them into your character.
@@Enderking-pt4ux thank bud
I get an Error "The name'Keycode' does not exist in the current context" pls help
Hi, I have made my terrain to be in even like going up and down a hill, my character is not staying on the ground, it starts on it but as soon as the terrain is uneven the character floats. Can you please help me
You need to decerase your capsule height from Capsule Collider section.
my character is moving endlessly if i press any key , anyone help me with this problem?
12:26, mines still buggy, dosnt go back
also the animation gets stuck sometimes
character also dosnt turn
the walk speed also sometimes increases twice when i press shift, like for example, i press shift and stop wlaking, i do it again and the speed is240, again and its like 400
also, initially the walk speed and walk back speed is really slow and seems like its not moving
edit: it seems ive fixed the turning but not the speed problem
@@hazen7645 I'll check it out
Can you explain how you fixed it?
@@unknownbro9857 just make sure your colliders are lined up and everything in the code is correct
@@aprizuniverse ok i will check it out
Thnx a lot! 🫡🌟
Why when I go backwards it teleports me to the center over and over again.But when i go forwards i dont get teleported?
when you download the backwalk animation, you didn't check inplace
thanks m8 @@pandu7903