I have seen a lot of people struggling over the player not being able to jump while looking down or having their player model rotate with the camera, i had the same exact issue. So after a little bit of trial and error i came up with this solution: You need to go to the part where it says: Vector3 move = transform.right * x + transform.forward * z; Replace that line for this Vector3 move = Camera.transform.right * x + Camera.transform.forward * z; And at the start of the code add this: public transform Camera; Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck Finally, grab the Mouse script, remove it from the player and add it to the camera object I hope this works for all of you and try to make this comment get to the top so more people can see it, love from Argentina Check replies if it doesnt work
@@shrenikmunot9897 how about adding a head to the body and applying the rotating transforms only on the head so the body(and ground check object) won't tilt and cause problems with the jumping...
@@rambdube A little while after commenting this i kind of did that, what i did was create an empty game object named "orientation" and placing it at the head of the body. Then modified the player code again to say the following: Vector3 move = Orientation.transform.right * x + Orientation.transform.forward * z; Then i created a new script named orientation. I copied the camera script on to it, BUT, removed the part that allowed it to move vertically, so the camera and the orientation are alligned in the X axis, but not on the Y axis, this way, if you look up or down you still move forward and not fly into the air or move slower. Also, you will need to add this public transform Orientation; Go to player inspector, script variables, and drag the orientation game object. Then just add the orientation script to the orientation object
For those who cannot move and jump, you must change the height of your console character, and make sure your foundation is not too far from your body so that the system can read it correctly, not too low or too high, and for ground checks it must also be in accordance with the ideal number.
Im here again , this time i watch this series again, to understand the code, next time please be a bit slowly, but anyway, you make the best tutorial ever exist on youtube!
Love your tutorials man, you're a good teacher! I'm just going through them all so I can learn more If anyone is using Unity 2022.3.16f1 and their for Mouse Rotation isn't working - my VS/Unity combo doesn't like negative defaults for some reason - so when you change the topClamp to -90 in your IDE/Script Editor, check the Inspector mine still said 90, this isn't the first time I've seen this
Found something interesting. You can't jump while looking down. Probably because the camera controller is connected to the whole player and not just the camera so the ground check leaves the ground when u look up or down but idk. I'm no coder.
you are right, the whole thing rotates down and up. This is also inconvenient for enemy encounters, since the player can look up or down to dodge bullets or attacks because the hitbox of the player is connected to it Edit: I just found the solution. You need to go to the part where it says: Vector3 move = transform.right * x + transform.forward * z; Replace that line for this Vector3 move = Camera.transform.right * x + Camera.transform.forward * z; And at the start of the code add this: public transform Camera; Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck Finally, grab the Mouse script, remove it from the player and add it to the camera object I hope i explained it right and it works for you
yeah your entire player rotates, thus the ground check is levitating, while your body is keeping you from falling below the floor. I spend an unholy amount of time debugging that
@@meth2326 what I ended up doing is I made an empty head object, attached a sphere and the camera to that, and made the body rotate aroundthe y axis based on the head rotation. Player movement is on the player object and mouse movement on the head object
help when looking it rotates the entire character and won't jump because the ground check is no longer detects the ground cus the ground check sideways
@Mikes-Code with your MouseMovement script you have the Player rotation on the x and z axis frozen so that the PlayerBody doesn't tilt in all directions. Care to explain how you did that as this is an issue that is apparently common amongst your viewers.
im at the end of the tutorial and everything is working but i automatically move backwards when i press play and i cant make it stop, i can counteract by walking forward but not stop it, the automatic backwards movement is slightly slower than normal movement since i can walk forward but very slowly
i realised its probably because of my g920 that was plugged in and after unplugging and restarting unity editor it works again, just replying this in case anyone gets same problem and has a steering wheel or other controller plugged in that may interfere
i have several issues and those are 1- groundCheck is always true 2- player moving everywhere looking at. Including up and down 3- player gliding down whether gravity is too high or low.
Transform.localRotation won’t work it says the problem is (CS0120) and An object reference is required for the non-static field, method, or property plz help Edit : NVM CHAT GPT DA GOAT
Assets\Scripts\MouseMovement.cs(13,11): error CS1519: Invalid token 'float' in class, record, struct, or interface member declaration. How can i fix this?
Hi, @Mike! Please can you help me - my Player doesn't want to Jump! His velocity always decreases and I don't know how to fix it. In debugger I checked what line " velocity.y = Mathf.Sqrt(_jumpHeight * -2f * _gravity);" executes, bot no effect! Please help, what I missed? Thank you
Hi, im new to this unity stuff and i dont really understand on that code thing you type, can you make a tutorial for a real beginners on how to use one? Really enjoy on your video though, you are a great teacher.
Can anyone help me with this? So i followed this whole video through yet afterwards i realized the entire body was rotating instead of just the camera, i dont know if this is correct because, since the entire body moves then when i am looking 90 degrees down then i cant just (because groundCheck is lifted off the ground). This also causes the issue where i cant move with w or d while looking down because my character is moving forwards (which is in this case down because im looking down). This makes it so looking down even a little slows down my character. Is there any way to fix this? Btw: I cannot just set the bottom clamp to lower because it still slows me down when im looking even slightly downwards
You need to go to the part where it says: Vector3 move = transform.right * x + transform.forward * z; Replace that line for this Vector3 move = Camera.transform.right * x + Camera.transform.forward * z; And at the start of the code add this: public transform Camera; Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck Finally, grab the Mouse script, remove it from the player and add it to the camera object I hope i explained it right and it works for you
I had a problem with the character doing this hopping movement when they looked too far up so I made a slight change. Inside the PlayerMovement script, inside the Update method, I got rid of the CheckSphere raycast and replaced it with a regular Raycast, checking from the groundCheck position, downwards, for a length of groundDistance, still checking for groundMask. Back in Unity, I positioned the GroundCheck object in the center of the Player object and made the groundDistance value 2, since the body is scaled to 1.7. Basically the distance needs to be slightly higher than the player Y scale. I don't know if this will conflict with anything in the future though because I've only completed the first two videos. Technically don't need the Debug line, but it's nice to see isGrounded = Physics.Raycast(groundCheck.position, Vector3.down, groundDistance, groundLayer); Debug.DrawLine(groundCheck.position, groundCheck.position + Vector3.down * groundDistance, Color.red); if (isGrounded && velocity.y < 0) { velocity.y = -2f; }
Make this your movement script if you want to be able to sprint when holding "Shift": using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { private CharacterController controller; public float speed = 12f; public float sprintSpeed = 18f; // Add a sprint speed public float gravity = -19.62f; // More realistic gravity public float jumpHeight = 3f; public Transform groundCheck; public float groundDistance = 0.4f; public LayerMask groundMask; private Vector3 velocity; private bool isGrounded; public Transform Camera; void Start() { controller = GetComponent(); } void Update() { GroundCheck(); Move(); } void GroundCheck() { isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); if (isGrounded && velocity.y < 0) { velocity.y = -2f; // Reset velocity when grounded } } void Move() { float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); Vector3 move = Camera.transform.right * x + Camera.transform.forward * z; // Check if the Shift key is pressed to sprint if (Input.GetKey(KeyCode.LeftShift)) { controller.Move(move * sprintSpeed * Time.deltaTime); } else { controller.Move(move * speed * Time.deltaTime); } if (isGrounded && Input.GetButtonDown("Jump")) { velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity); } // Apply gravity velocity.y += gravity * Time.deltaTime; // Apply final movement with gravity controller.Move(velocity * Time.deltaTime); } }
@@tohiroGm that is because you are a sphere right now and when you look up you and your sphere collider also look up with you therefore your jump point isn’t on the ground when looking up or down I don’t know how to fix this problem tho
I wonder if this course will show us how to make our own weapons instead of getting free premade assets. I'd really like to learn how to make weapons, probably something done in blender.
It did not work for me. It said, [16:13:30] Assets\Scripts\MouseKovement.cs(27,24): error CS0131: The left-hand side of an assignment mus be a variable, property or indexer
@@yonaberrebi2452 well, you can technically borrow some of code, lets say, the weapon logic to work in VR, but most of the tutorial is not compatible with VR and is not going to work, unless you know how to create your own VR controls. The problem is that VR deals with movement/controls/interactions in a completely different way.
why is my camera so strange, I followed the whole video very well but nothing works, the body follows the movement of the camera, the movement of the player is like this part did not persist, so I need help
@@Saroshxeditzz With help from a friend, I removed the cillinder collider and increased the height of the "character controller" on the Player to cover the whole figure (you can see the lines of the colliders to compare) and that stopped the falling.
ummmm teres a problem im having wen i look doun all the way and try to jump i cant same gose to wen i look up all the wai to the max i stil cant jump do you noue wi or if tere is a problem in the code tat make it not let me jump?
@@legoalternator2.014 Thats becouse you rotate your playerprefab when you look up/down. So your groundcheck will be in the "air" and then you cant jump. Look up/down should only effect camera and not the rotation of player body
@@jclouis7117 hey, what happens when you press on play? Is the game running? Are you getting any errors in the console? Did you make sure the scripts are saved and placed on the player correctly. That the camera is a child of the player?
Hi. I got stuck here: error CS1503: Argument 2: cannot convert from 'UnityEngine.Transform' to 'float' how to fix it? i can't find the right place in my code.
This is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { private CharacterController controller; public float speed = 12f; public float gravity = -9.81f * 2; public float jumpHeight = 3f; public Transform groundCheck; public float groundDistance = 0.4f; public LayerMask groundMask; Vector3 velocity; bool isGround; bool isMoving; private Vector3 lastPosition = new Vector3(0f, 0f,0f); void Start() { controller = GetComponent(); } // Update is called once per frame void Update() { // Ground Check isGround = Physics.CheckSphere(groundCheck.position, groundCheck, groundMask); // Resetting the default velocity if(isGround && velocity.y
@@Mikes-Code This is the entire line of the error: [12:07:44] Assets\Scripts\PlayerMovement.cs(37,62): error CS1503: Argument 2: cannot convert from 'UnityEngine.Transform' to 'float' if you still have the code can you send it to me so i can cope and past it? sometime that is how t i can fix this problems.
@@012-prog I actually don't really know any good c# tutorials, although I'm sure they are out their. Just look for a complete one, and take it slow, learn all the basics.
Please add storage system like we could place our inventory items inside chest and could you make a system for random items inside chest for looting purpose in your survival series please...
Yes the survival series will still continue. There is actually no real reason that I use this input system. But maybe I will change it in the future, if I see that it limits us in some way.
Guy named "Eric5h5" in Unity Forum: "The documentation is correct on both counts; it’s not a matter of “which one is it”. GetAxis(“Horizontal”) by default is keyboard input and has nothing to do with mouse movement. GetAxis(“Mouse X”) is mouse movement and is always inherently framerate-independent: if you move your mouse two inches, it takes the same time for you to do that regardless of how fast your computer is. (If the framerate affects your own physical movement speed, I would start to worry. :wink: ) So you should absolutely not use Time.deltaTime with mouse movement, since that will cause the code to become framerate-dependent."
try to use Debug.log(isGrounded); If the value is Flase the player is not on the ground and if its true is on the ground. The problem with jumping is that the groundDistance = 0.4f is low value for the radius of the CheckSphere. So basically if u are looking down or up the GroundCheck(the empty body under the player) is way to far from the ground. Try to set the value of groundDistance to 5.
You neeed to explain wha you are doing, you do everything sp fast its so hard to follow even if you set the playbackspeed slower, You somehow access something we dont know how to do what you did because you dont explain it.
Hey, as mentioned at the beginning of this series, it is a rather fast-paced series, not meant for beginners. It is for developers who are comfortable with Unity and just want to know how to add FPS elements to their game. For example, my Survival series is for beginners and it starts very slowly where I explain everything. I still think it is possible for beginners to follow along with this series, it will just require a higher learning curve.
I'm excited about this new series, I signed up for the survival series, I'm also going to follow this one!!
I have seen a lot of people struggling over the player not being able to jump while looking down or having their player model rotate with the camera, i had the same exact issue. So after a little bit of trial and error i came up with this solution:
You need to go to the part where it says:
Vector3 move = transform.right * x + transform.forward * z;
Replace that line for this
Vector3 move = Camera.transform.right * x + Camera.transform.forward * z;
And at the start of the code add this:
public transform Camera;
Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck
Finally, grab the Mouse script, remove it from the player and add it to the camera object
I hope this works for all of you and try to make this comment get to the top so more people can see it, love from Argentina
Check replies if it doesnt work
Unfortunately , it still does not work , do you have any other solutions ?
@@shrenikmunot9897 how about adding a head to the body and applying the rotating transforms only on the head so the body(and ground check object) won't tilt and cause problems with the jumping...
@@rambdube A little while after commenting this i kind of did that, what i did was create an empty game object named "orientation" and placing it at the head of the body. Then modified the player code again to say the following:
Vector3 move = Orientation.transform.right * x + Orientation.transform.forward * z;
Then i created a new script named orientation. I copied the camera script on to it, BUT, removed the part that allowed it to move vertically, so the camera and the orientation are alligned in the X axis, but not on the Y axis, this way, if you look up or down you still move forward and not fly into the air or move slower.
Also, you will need to add this
public transform Orientation;
Go to player inspector, script variables, and drag the orientation game object. Then just add the orientation script to the orientation object
@@meth2326 не работает(
Thanks
For those who cannot move and jump, you must change the height of your console character, and make sure your foundation is not too far from your body so that the system can read it correctly, not too low or too high, and for ground checks it must also be in accordance with the ideal number.
Im here again , this time i watch this series again, to understand the code, next time please be a bit slowly, but anyway, you make the best tutorial ever exist on youtube!
I waited for this series alsoooo, i finish(till now) the survival game tutorial and im also going to follow this one, cant wait for the learning !!!!!
So stoked for this series!
Hello :) Excited to start this series :)
This is awesome, working on my first shooter and excited to continue!
Love your tutorials man, you're a good teacher! I'm just going through them all so I can learn more
If anyone is using Unity 2022.3.16f1 and their for Mouse Rotation isn't working - my VS/Unity combo doesn't like negative defaults for some reason - so when you change the topClamp to -90 in your IDE/Script Editor, check the Inspector mine still said 90, this isn't the first time I've seen this
Found something interesting. You can't jump while looking down. Probably because the camera controller is connected to the whole player and not just the camera so the ground check leaves the ground when u look up or down but idk. I'm no coder.
you are right, the whole thing rotates down and up. This is also inconvenient for enemy encounters, since the player can look up or down to dodge bullets or attacks because the hitbox of the player is connected to it
Edit: I just found the solution. You need to go to the part where it says:
Vector3 move = transform.right * x + transform.forward * z;
Replace that line for this
Vector3 move = Camera.transform.right * x + Camera.transform.forward * z;
And at the start of the code add this:
public transform Camera;
Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck
Finally, grab the Mouse script, remove it from the player and add it to the camera object
I hope i explained it right and it works for you
@@meth2326 For those of you who are getting an error trying this, change public transform Camera; to public Transform Camera;
@@meth2326 I encountered a problem. When you look up and hold forward you fly forward.
yeah your entire player rotates, thus the ground check is levitating, while your body is keeping you from falling below the floor. I spend an unholy amount of time debugging that
@@meth2326 what I ended up doing is I made an empty head object, attached a sphere and the camera to that, and made the body rotate aroundthe y axis based on the head rotation. Player movement is on the player object and mouse movement on the head object
if you want to sprint, simply set the movement speed to increase if ur pressing leftshift
If having trouble with jumping not working, increase the ground distance within the player movement script (0.4 to 2.0 worked for me).❤
you saved meeeee with this
Thanks a LOT
It solved the problem
Also if it still doesn't work you have to also change it in the inspector
Personal bookmarks
1:27
2:38 MouseMovement script, coding.
you deserve more subs becuse you are a good game dev an your a amazing
this series looks really good
love this man thank you so much.
im gonna use this series to help me build a fun shooter similar to ow
help when looking it rotates the entire character and won't jump because the ground check is no longer detects the ground cus the ground check sideways
why are you using the physics.checksphere when also using a character controller? there is a .IsGrounded bool in the CharacterController class
@Mikes-Code with your MouseMovement script you have the Player rotation on the x and z axis frozen so that the PlayerBody doesn't tilt in all directions. Care to explain how you did that as this is an issue that is apparently common amongst your viewers.
Why i fly not walking😂😂
thank you a very good teacher
Just subbed for your Survival game and then this drops...... so excited !
when i jump while looking straight i start falling slower than when i jump up and when i look down it looks normal how do i fix this?
This series is very halpful and awesome can you make some series like this we are interested this content love you sir 🤩🤩🤗🤗🥰🥰🥰🥰🥰🥰😍😍😍😍😍😍
wow, I find this great series.woo - hoo🥰🥰
what was the cut at 2:30 where the plane just got rlly big for??? idk how to make it look like that and it ruins the game
just upscale the plane my guy😭
im at the end of the tutorial and everything is working but i automatically move backwards when i press play and i cant make it stop, i can counteract by walking forward but not stop it, the automatic backwards movement is slightly slower than normal movement since i can walk forward but very slowly
i realised its probably because of my g920 that was plugged in and after unplugging and restarting unity editor it works again, just replying this in case anyone gets same problem and has a steering wheel or other controller plugged in that may interfere
When I try to open the project it just says Project failed to open (This project is not valid) what should I do?
i have several issues and those are
1- groundCheck is always true
2- player moving everywhere looking at. Including up and down
3- player gliding down whether gravity is too high or low.
you are very underated
wow Thank you!
you are the best Teacher that i see in my life ❤
Transform.localRotation won’t work it says the problem is (CS0120) and An object reference is required for the non-static field, method, or property plz help
Edit : NVM CHAT GPT DA GOAT
thank you and I love you man
Everything is not working, I cannot jump, I instantly fly away XD
yes me too XD
@@kamilbrawl1218check the gravity parameter in the inspector
Decrease jump power
thanks mike's code i done my game
Assets\Scripts\MouseMovement.cs(13,11): error CS1519: Invalid token 'float' in class, record, struct, or interface member declaration. How can i fix this?
hey, there seems to be a probelm on line 13, of the mousemovement script. could you paste line 13?
At 3:26 how did you put that special character that was after the "xRotation"?
This is just the "minus" character - and the "equals" character =.
Hi, @Mike!
Please can you help me - my Player doesn't want to Jump!
His velocity always decreases and I don't know how to fix it.
In debugger I checked what line " velocity.y = Mathf.Sqrt(_jumpHeight * -2f * _gravity);" executes, bot no effect!
Please help, what I missed?
Thank you
take away the underscores
beautiful, thank u
Hi, im new to this unity stuff and i dont really understand on that code thing you type, can you make a tutorial for a real beginners on how to use one? Really enjoy on your video though, you are a great teacher.
@@alexchrist9796 actually, a c# tutorial for begineers is planned in the near future.
Can anyone help me with this? So i followed this whole video through yet afterwards i realized the entire body was rotating instead of just the camera, i dont know if this is correct because, since the entire body moves then when i am looking 90 degrees down then i cant just (because groundCheck is lifted off the ground). This also causes the issue where i cant move with w or d while looking down because my character is moving forwards (which is in this case down because im looking down). This makes it so looking down even a little slows down my character. Is there any way to fix this?
Btw: I cannot just set the bottom clamp to lower because it still slows me down when im looking even slightly downwards
Having the exact same problem
You need to go to the part where it says:
Vector3 move = transform.right * x + transform.forward * z;
Replace that line for this
Vector3 move = Camera.transform.right * x + Camera.transform.forward * z;
And at the start of the code add this:
public transform Camera;
Then go to the player inspector, go to the script part and drag the camera in the transform section similar to groundcheck
Finally, grab the Mouse script, remove it from the player and add it to the camera object
I hope i explained it right and it works for you
I had a problem with the character doing this hopping movement when they looked too far up so I made a slight change.
Inside the PlayerMovement script, inside the Update method, I got rid of the CheckSphere raycast and replaced it with a regular Raycast, checking from the groundCheck position, downwards, for a length of groundDistance, still checking for groundMask.
Back in Unity, I positioned the GroundCheck object in the center of the Player object and made the groundDistance value 2, since the body is scaled to 1.7. Basically the distance needs to be slightly higher than the player Y scale.
I don't know if this will conflict with anything in the future though because I've only completed the first two videos. Technically don't need the Debug line, but it's nice to see
isGrounded = Physics.Raycast(groundCheck.position, Vector3.down, groundDistance, groundLayer);
Debug.DrawLine(groundCheck.position, groundCheck.position + Vector3.down * groundDistance, Color.red);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
Make this your movement script if you want to be able to sprint when holding "Shift": using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private CharacterController controller;
public float speed = 12f;
public float sprintSpeed = 18f; // Add a sprint speed
public float gravity = -19.62f; // More realistic gravity
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
private Vector3 velocity;
private bool isGrounded;
public Transform Camera;
void Start()
{
controller = GetComponent();
}
void Update()
{
GroundCheck();
Move();
}
void GroundCheck()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f; // Reset velocity when grounded
}
}
void Move()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = Camera.transform.right * x + Camera.transform.forward * z;
// Check if the Shift key is pressed to sprint
if (Input.GetKey(KeyCode.LeftShift))
{
controller.Move(move * sprintSpeed * Time.deltaTime);
}
else
{
controller.Move(move * speed * Time.deltaTime);
}
if (isGrounded && Input.GetButtonDown("Jump"))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
// Apply gravity
velocity.y += gravity * Time.deltaTime;
// Apply final movement with gravity
controller.Move(velocity * Time.deltaTime);
}
}
Hi, very cool everything works! Can you please tell me if you have fixed the fact that the player does not go looking down or bounces looking up?
@@tohiroGm that is because you are a sphere right now and when you look up you and your sphere collider also look up with you therefore your jump point isn’t on the ground when looking up or down I don’t know how to fix this problem tho
@@PrismX_8 I agonized with this shit for a long time, decided to just limit the viewing angle in the game
@@tohiroGm that could work you could also mabye but three different jumping points or ask chat gpt
I wonder if this course will show us how to make our own weapons instead of getting free premade assets. I'd really like to learn how to make weapons, probably something done in blender.
so this basically works except the fact that I can fly and I have exactly the same code
My character controller collides with the plane, making it falls on gameplay. Any tips?
check colliders and make sure that player up to the platform
more specifically, you can remove the cillinder collider and increase the height of the "character controller" on the Player to cover the whole figure
All works except jump, on a MacBook pro mousepad works but space bar not allowing jump. Anything I need to change in the Project settings??
It did not work for me. It said,
[16:13:30] Assets\Scripts\MouseKovement.cs(27,24): error CS0131: The left-hand side of an assignment mus be a variable, property or indexer
Yeah i got that too
I had that and just realised that the symbol just after the (“Mouse X”) is an asterisk * not an equals sign
it is aproblem if i use Unity VR Project?
@@yonaberrebi2452 well, you can technically borrow some of code, lets say, the weapon logic to work in VR, but most of the tutorial is not compatible with VR and is not going to work, unless you know how to create your own VR controls.
The problem is that VR deals with movement/controls/interactions in a completely different way.
@@Mikes-Code okay thanks
why is my camera so strange, I followed the whole video very well but nothing works, the body follows the movement of the camera, the movement of the player is like this part did not persist, so I need help
Error with the cursor : Cannot implicitly convert type 'UnityEngine.CursorLockMode' to 'UnityEngine.Cursor'
Same
Did you fix it
Yeah, I fixed it. I found a mistake in my code
Just look carefully through your code
the code doesnt work. it compile fine but the character doesnt move
works for me
@@beanboi3178 how man? how?
@@ssrs9661 idk, I’m not great at coding, i just copied everything in the video and it worked, maybe you missed something in the unity editor or code
same here, I did everything he said and nothing happens
@ssrs9661 try to add the script in the player from add component option
As soon as I fixed an error involving the jump input, I started falling through the ground when I enter play mode. What should I do?
Make sure the player is above the ground, and that he has a collider, also the ground should have a collier
how did you solved it
@@Saroshxeditzz With help from a friend, I removed the cillinder collider and increased the height of the "character controller" on the Player to cover the whole figure (you can see the lines of the colliders to compare) and that stopped the falling.
I have a problem when I spin my camera the character moves also
The smartest John. You need MouseMovement ONLY ON THE CAMERA
Is there a particular reason why you're using xRotation on the player transform.x instead of the camera.transform.x?
ummmm teres a problem im having wen i look doun all the way and try to jump i cant same gose to wen i look up all the wai to the max i stil cant jump do you noue wi or if tere is a problem in the code tat make it not let me jump?
but wen mi camera is straight i stil kan jump
forgot to mention
@@legoalternator2.014 Thats becouse you rotate your playerprefab when you look up/down. So your groundcheck will be in the "air" and then you cant jump. Look up/down should only effect camera and not the rotation of player body
hello im not able to move my camera ( 6.:10)on play mode pls help im strugling
@@jclouis7117 hey, what happens when you press on play? Is the game running? Are you getting any errors in the console? Did you make sure the scripts are saved and placed on the player correctly. That the camera is a child of the player?
Which Engine Version are you using?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private CharacterController controller;
public float speed = 12f;
public float gravity = 9.81f * 2;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
bool isMoving;
private Vector3 lastPosition = new Vector3(0f, 0f, 0f);
// Start is called before the first frame update
void Start()
{
controller = GetComponent();
}
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
if (lastPosition != gameObject.transform.position && isGrounded == true)
{
isMoving = true;
}else
{
isMoving = false;
}
lastPosition = gameObject.transform.position;
}
}
Hi.
I got stuck here: error CS1503: Argument 2: cannot convert from 'UnityEngine.Transform' to 'float'
how to fix it?
i can't find the right place in my code.
Please paste the entire error code, it should say in which script, and even on what line is the error.
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f * 2;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGround;
bool isMoving;
private Vector3 lastPosition = new Vector3(0f, 0f,0f);
void Start()
{
controller = GetComponent();
}
// Update is called once per frame
void Update()
{
// Ground Check
isGround = Physics.CheckSphere(groundCheck.position, groundCheck, groundMask);
// Resetting the default velocity
if(isGround && velocity.y
Please help?
@@galberger3937 hey, can you post the entire error description?
@@Mikes-Code This is the entire line of the error:
[12:07:44] Assets\Scripts\PlayerMovement.cs(37,62): error CS1503: Argument 2: cannot convert from 'UnityEngine.Transform' to 'float'
if you still have the code can you send it to me so i can cope and past it?
sometime that is how t i can fix this problems.
Mike can you tell me place to learn c# from 0% to 100% please reply me
@@012-prog I actually don't really know any good c# tutorials, although I'm sure they are out their.
Just look for a complete one, and take it slow, learn all the basics.
go to pluralsight. Good courses and learning paths.
Please add storage system like we could place our inventory items inside chest and could you make a system for random items inside chest for looting purpose in your survival series please...
he will he just started
With the MouseMovememt script it has a bunch of errors like it already has a definition for mousemovement and stuff
cab you get gun model form sketfab ?
I followed the tutorial and in the end my character keeps going up in the sky and never stops. ant tips on how to fix that??
Gravity on the rigidbody?
@@eatower2 you mean the player movement script??? Its 19.62 on it and the speed is 12 and the jump height is 3
@@ret4rd3dmonk try -19.62?
@@ret4rd3dmonk did you try it at - 19.26?
Not finishing survival series?
I think he will continue it but later
The survival series will still continue. New episode soon.
This FPS series is still experimental, i want to see if people even like it.
@@Mikes-Code ok thanks, was just wondering, take your time
@@Mikes-Code I like the fps design btw
I don't know why but I instantly fly ive tried fixing the position but no result
make sure your gravity is negative. That happened to me but once I changed the gravity to negative I was fine.
Is there download link to this game it seems fun !! I love the vids 🔥🔥
can you make a full FPS multyplayer tutorial ?
Thank you it was so clear explain thats great for me (this Series awesome)
how did you got this code theme in visual studio pls tell then i will subscribe ok
I had to make my Top Clamp = 90 and Bottom Clamp = -90 in unity 2022.3.25 for it to work right. Player Body was falling over otherwise.
did you solved problem
my character whole body is moving can anyone help me?
after applying mousemovement script, my character body is rotating
Hey, so weird question, but can you make enemies that attack with ranged weapons like guns and as well melee, cuz i do wanna make both for my game.
Are you going to continue the survival series as well as this ? Also why do you choose the old input system over the new one ?
Yes the survival series will still continue.
There is actually no real reason that I use this input system. But maybe I will change it in the future, if I see that it limits us in some way.
i thought mouse inputs are already frame independent arent they?
Guy named "Eric5h5" in Unity Forum:
"The documentation is correct on both counts; it’s not a matter of “which one is it”. GetAxis(“Horizontal”) by default is keyboard input and has nothing to do with mouse movement. GetAxis(“Mouse X”) is mouse movement and is always inherently framerate-independent: if you move your mouse two inches, it takes the same time for you to do that regardless of how fast your computer is. (If the framerate affects your own physical movement speed, I would start to worry. :wink: ) So you should absolutely not use Time.deltaTime with mouse movement, since that will cause the code to become framerate-dependent."
The thumbnail 😂
Anyone got the code? i tried recreating it myself but the clamps wont work and the sensitivity is whack
I've used roblox studio and learned the layout... do you think this is enough to be able to follow along with this? ;>
I'm stuck here: I wrote the same script as you, but somehow I can float, why?
-19.62 for gravity
the "z" in movement code in not working
the character isnt jumping please help
try to use Debug.log(isGrounded); If the value is Flase the player is not on the ground and if its true is on the ground. The problem with jumping is that the groundDistance = 0.4f is low value for the radius of the CheckSphere. So basically if u are looking down or up the GroundCheck(the empty body under the player) is way to far from the ground. Try to set the value of groundDistance to 5.
One small problem, it still lets me jump infinitely
my character cant look top and down its blocked but not correct
Top for me❤
when i look around the camera moves
i guess you have to parent it to the player if you did this you need to add the script with the mouse to the camera i think but idk
hey im having a problem with this error Assets\Scripts\MouseMovement.cs(21,48): error CS1002: ; expected do you think you can help
can anyone provide me the script of player movements plz?
Strange? but i'm tottali copied this code and game still not seeing mouse
Same
thx for the movement but i cant jump
can i have link for codes🙏
when i look around my hole player bod moves
Can Mr.mike or anyone pls provide all the codes required in this entire project within 2 days 🙏🙏
Who has done it already can help too
Because I Am a beginner and struggling a lot
why using old input system?
You can use the new one if you want.
I just don't like it.
I can't jump😢 space isn't working? I did everything as you said
bro adjust your ground check position keep it close to the player feet. I had also the same problem but now it is working goood😊
I can't open the scrips
@@BlueGuyBR12345 Do you have a code editor installed? When you install a new Unity Version it always offers to install Visual Studio.
For some reason Jumping did not work for me.
A Question
You neeed to explain wha you are doing, you do everything sp fast its so hard to follow even if you set the playbackspeed slower, You somehow access something we dont know how to do what you did because you dont explain it.
Hey, as mentioned at the beginning of this series, it is a rather fast-paced series, not meant for beginners.
It is for developers who are comfortable with Unity and just want to know how to add FPS elements to their game.
For example, my Survival series is for beginners and it starts very slowly where I explain everything.
I still think it is possible for beginners to follow along with this series, it will just require a higher learning curve.
True
Facts
Pls can you provide all the codes