This helped me understand the input system better thank you. A request for a future video or series, a Sprint like GTA where you button mash. Nobody seems to have a video on button mash to sprint. They all use "hold shift down".
My first thought for that is to create a speed multiplier variable with a default value of 1. Then everytime you press the button, you increase it by a small amount until it reaches the max value. To get the deceleration part, you could either subtract a small amount from the multiplier each frame (This would be a very linear deceleration). Or, maybe do something like Multiplier *= .9 I can think about it a bit more, but that would be my first approach.
@@sodarocketstudios Thanks for the quick reply. Forgive me Im new so I understand what you're suggesting but not the code. Hopefully when you get time you can make a video on it. It would be something nobody else has covered. Thanks again tho. Peace
Thanks! I don't have a video on it, but what you are looking for are called blend trees. Then, you just need to multiply the speed by a sprint multiplier in the movement code.
im having issues with the player controller script (not having the Move Speed*) and when i try to add the OnMove* to the Player Input/Events/Control, it doesnt pop up for me? could i have done the script wrong? im a first time use to unity so everything is new to me. Thank you in advance for the help
For the Move speed, do you have [SerializeField] before the vector declaration? I.e. [SerializeField] private float MoveSpeed; and for the onMove function you need to make sure you use the Public keyword so: public void OnMove. The other problem would be if the function doesn't accept a callback context. In that case you want it to look like this, OnMove(InputAction.CallbackContext context). I assumed you meant that these things weren't showing up in the inspector, which is the window in the unity editor that shows you all of the components on a selected game object. If that is the case, then it is most likely you are missing something I described above. Otherwise, I may have misunderstood your problem. If this doesn't fix your problems I can try to help you walk through it more.
@@sodarocketstudios yeah, I made sure the script matches what you provided, I wonder if it's because I'm using an updated version of unity? and yes if you are free to walk me through it would greatly appreciate it!
Let's start with the Move speed then, since it will probably be easier to solve. If you can give me some more detail on the problem, it will help me figure what is going on.
@@sodarocketstudios (using this code) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class PlayerController : MonoBehaviour { [SerializeField] private float moveSpeed = 1; private Vector2 moveVector; private CharacterController characterController; // Start is called before the first frame update void Start() { characterController = GetComponent(); } // Update is called once per frame void Update() { Move(); } public void OnMove(InputAction.CallbackContext context) { moveVector = context.Readvalue(); } private void Move() { Vector3 move = transform.right*moveVector.x + transform.forward*moveVector.y; characterController.Move(move*moveSpeed*Time.deltaTime); } }
That was a tricky one to catch. The error was only useful for pointing out where it was, but I believe the issue is that you didn't capitalize the v in ReadValue in your OnMove function.
In the input control's where you made the jump function If I add in another a 3rd button F for Fly what button on a controller would you make it I was thinking L3 or so R3 can be dash or run
You can use any button you want. Personally, I like the idea of reusing the jump button and in the OnJump method add, if (isGrounded) then jump else fly.
Hi! First of a all, Great Video! The problem I'm facing is that OnJump function is not showing in player input events however the OnMove and OnLook are working perfectly fine! Any Idea What could be the reason for the same? Your Explanation is Top Notch and you earned yourself a subscriber!
If you could paste the header of your on jump function, it might be a bit easier. The most basic errors I can think of that would cause that are having OnJump set to private, or if you have a parameter other than a callback context.
The most common method is to create an empty parent object that contains the object with the player model as a child. Then, you can adjust the location of the child object with the model on it until the feet are on the ground.
I'm guessing you got a sign wrong somewhere, make sure the gravity is applying a negative y to the velocity. I changed my mind on where I put the negative sign in the video, so I wouldn't be surprised if you set gravity as negative and then in the on move you have another negative sign canceling it out.
@@sodarocketstudios Thanks. I fixed the gravity sign. Your code works great! I added a mesh collider to the 3D scene, then the character won't keep falling out of the scene. :D
It's a function that you have to create before you can connect it to the input system. If you did make it, then make sure it is public. If you don't specify it is set to private by default and you won't be able to see it.
If you pass in a reference to the cinemachine virtual camera, you can adjust the z component of the follow offset to move the camera up and down. it might be easier to setup the camera like I do in this video ruclips.net/video/dqfVlSxOXv8/видео.html.
I created a unity package of the project and put a link to it in the description. You will need to make sure you install cinemachine and the input system package to get it to work right.
The easiest way to fix it is to walk through each part and check it. I would start by making sure your input action is set up correctly. Then make sure you have connected the jump method to the jump action on the player input manager. If both of those are correct, then it is likely something wrong with the jump function. If it is a problem with code, I will need to know more to help.
Hi. I followed your tutorial until 8:31 but when I press the play button, it isn't my character that is moving but the camera itself. How to fix this? My camera is the one that is moving not the character.
@@kurtlosbanos6123 I'm not sure how that happens since I use a character controller to move the character. Unless your character is a child object of the camera, but then both would be moving. are your character and camera two completely separate game objects?
I can definitely start looking into it. I might do something a bit less specific to try and keep it useful for more people. This is just a guess, but I suspect that for something like guns, instead of making character animations for each specific gun, you could put target points on the gun and use inverse kinematics (I'm not an expert at animation, so this could be very wrong.). I played with that a tiny bit when I was making the Mixamo video. I can start researching, and, if it looks like an approach that makes sense, I can make a video explaining how to do it. If I covered third-person shooter controls, I might make it it's own video. Were you thinking things like how to aim and setup a crosshair, then how to determine what the player is shooting?
I might try to do a video on the controls portion first. I think I would be able to get it out faster. I definetly recommend doing some research on it in the meantime if you need it soon.
@@sodarocketstudios what if statement where do a GetKeyDown press shift = increase the speed of the player and play the sprinting animation Will that work?
With how I setup the control script, I think the easiest way would be to add in a sprint input action. Then in the player controller script add an OnSprint function just like all of the other controls. In that function you will want to check the phase of the sprint button. If the phase is started(meaning the button was pressed) you can multiply the movement speed by some sprint speed multiplier. If the phase is canceled (meaning the button was released) you can then divide my that speed multiplier. So you will have: If(context.started) MovementSpeed*=sprintMultiplier If(context.canceled) MovementSpeed/=sprintMultiplier
@@sodarocketstudios is it possible that I can share my updated script with you on Twitter or something so that you can look into it , and if you can also tell me what could I change in animator window with sprint animation
On Twitter I am @SodaRocketDev. Or if you go to my channel, you can get my email (I don't want to put it in a comment to avoid bots). As for the animation part, I haven't done too much with animations so I can't tell you exactly what to do, but I can point you toward blend trees. I know there are several tutorials on them, and I think that might be what you are looking for.
instead of the mouse delta.x being added to the rotation vector, add the x component of the move input vector multiplied by some rotation speed value. I believe that will work. I am in a game jam right now, but If you need more help, I can try some things after this week.
@@vinesseyt The quick and dirty way you can accomplish this is to comment out ReadValue in the OnLook method, then in On move, change moveVector = context.ReadValue(); to moveVector.y = context.ReadValue().y; and right after that, add lookVector.x = context.ReadValue().x; Instead of telling the character to walk left or right, you are now telling the camera to rotate based on the A and D input. It will be very slow, so you may need to increase the sensitivity multiplier when setting the rotation.
The easiest way would be to create an empty game object under the character hierarchy. You will put this object where you want the eyes to be. then set the camera (Not a cinemachine virtual camera) as a child of the eyes object and set the position as (0,0,0).
@@sodarocketstudios this works great, but the player starts to randomly move around unless you move forward and I'm not sure how to make it so you can look left and right
@@BenGodot When you say it randomly moves, is it just walking on its own, or more like sliding? If it is walking around, then the only problem I can think of is that the motion vector isn't getting zeroed properly when you release the movement buttons. Looking left and right should be handled with the rotate method we created that will rotate the character around the y-axis. I am realizing now, that if you converted this controller to first person, then you wouldn't be able to look up and down, so you would need to add that by rotating the camera around its local x-axis based on the y value from the mouse delta. If you set it up to look up and down, but not left and right, then you want to rotate the character on the y-axis using the x component of the delta, and rotate the camera on its x-axis based on the y component of the mouse delta.
What part isn't working? It's possible that I had a mistake in the video, or something changed between different versions of unity. You aren't the only that seems to be having problems, so it might help others if we can work through it.
Dude, thank you so much! Finally found the video w/o any useless explanation and just straight to the point! Subscribed 👏👏
Amazing work and movement system setup. I was searching for this for months.
Thanks ❤️
Glad it helped!
This helped me understand the input system better thank you. A request for a future video or series, a Sprint like GTA where you button mash. Nobody seems to have a video on button mash to sprint. They all use "hold shift down".
My first thought for that is to create a speed multiplier variable with a default value of 1. Then everytime you press the button, you increase it by a small amount until it reaches the max value.
To get the deceleration part, you could either subtract a small amount from the multiplier each frame (This would be a very linear deceleration). Or, maybe do something like
Multiplier *= .9
I can think about it a bit more, but that would be my first approach.
@@sodarocketstudios Thanks for the quick reply. Forgive me Im new so I understand what you're suggesting but not the code. Hopefully when you get time you can make a video on it. It would be something nobody else has covered. Thanks again tho. Peace
The best tutorial ever, but one missimg thing sir, how can i make it from walking to running ? 😊
Thanks! I don't have a video on it, but what you are looking for are called blend trees. Then, you just need to multiply the speed by a sprint multiplier in the movement code.
Very Very helpful, TYVM
Thank you
love it
I've follwed and inputed the code for Jump but when I press play my player automatically shoots up into the air like a rocket.
Thank you so much!!! :)
No problem, I hope I covered everything you wanted to see.
@@sodarocketstudios I'm working right now. Tomorrow I can watch the whole video. 🤗
@@sodarocketstudios I really love it. It`s to the point and I understand everything you do. Thanks again!
project file is missing the most important file the player controller 😢
im having issues with the player controller script (not having the Move Speed*) and when i try to add the OnMove* to the Player Input/Events/Control, it doesnt pop up for me? could i have done the script wrong? im a first time use to unity so everything is new to me. Thank you in advance for the help
For the Move speed, do you have [SerializeField] before the vector declaration? I.e. [SerializeField] private float MoveSpeed; and for the onMove function you need to make sure you use the Public keyword so: public void OnMove. The other problem would be if the function doesn't accept a callback context. In that case you want it to look like this, OnMove(InputAction.CallbackContext context).
I assumed you meant that these things weren't showing up in the inspector, which is the window in the unity editor that shows you all of the components on a selected game object. If that is the case, then it is most likely you are missing something I described above. Otherwise, I may have misunderstood your problem. If this doesn't fix your problems I can try to help you walk through it more.
@@sodarocketstudios yeah, I made sure the script matches what you provided, I wonder if it's because I'm using an updated version of unity? and yes if you are free to walk me through it would greatly appreciate it!
Let's start with the Move speed then, since it will probably be easier to solve. If you can give me some more detail on the problem, it will help me figure what is going on.
@@sodarocketstudios (using this code)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float moveSpeed = 1;
private Vector2 moveVector;
private CharacterController characterController;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent();
}
// Update is called once per frame
void Update()
{
Move();
}
public void OnMove(InputAction.CallbackContext context)
{
moveVector = context.Readvalue();
}
private void Move()
{
Vector3 move = transform.right*moveVector.x + transform.forward*moveVector.y;
characterController.Move(move*moveSpeed*Time.deltaTime);
}
}
That was a tricky one to catch. The error was only useful for pointing out where it was, but I believe the issue is that you didn't capitalize the v in ReadValue in your OnMove function.
In the input control's where you made the jump function If I add in another a 3rd button F for Fly what button on a controller would you make it I was thinking L3 or so R3 can be dash or run
You can use any button you want. Personally, I like the idea of reusing the jump button and in the OnJump method add, if (isGrounded) then jump else fly.
Hi! First of a all, Great Video! The problem I'm facing is that OnJump function is not showing in player input events however the OnMove and OnLook are working perfectly fine! Any Idea What could be the reason for the same?
Your Explanation is Top Notch and you earned yourself a subscriber!
If you could paste the header of your on jump function, it might be a bit easier. The most basic errors I can think of that would cause that are having OnJump set to private, or if you have a parameter other than a callback context.
@@sodarocketstudios Sure Let me get back to you👍
how do i get the orientation box on character to its feet?
If you are talking about the collider, you should be able to move it around in the inspector until it matches up correctly.
@@sodarocketstudios No i mean the green ,red, and blue orientation box. mine is in the middle of my player.
The most common method is to create an empty parent object that contains the object with the player model as a child. Then, you can adjust the location of the child object with the model on it until the feet are on the ground.
@@sodarocketstudios thank you so much
Great tutorial, but jump seems not working. When I clicked on play, the character just kept flying and disappeared.
I'm guessing you got a sign wrong somewhere, make sure the gravity is applying a negative y to the velocity.
I changed my mind on where I put the negative sign in the video, so I wouldn't be surprised if you set gravity as negative and then in the on move you have another negative sign canceling it out.
@@sodarocketstudios Thanks. I fixed the gravity sign. Your code works great! I added a mesh collider to the 3D scene, then the character won't keep falling out of the scene. :D
Hey man i know this is a dumb question but for some reason i cant find the onmove in the player input
It's a function that you have to create before you can connect it to the input system. If you did make it, then make sure it is public. If you don't specify it is set to private by default and you won't be able to see it.
Great content and very nice explanation
If you pass in a reference to the cinemachine virtual camera, you can adjust the z component of the follow offset to move the camera up and down. it might be easier to setup the camera like I do in this video ruclips.net/video/dqfVlSxOXv8/видео.html.
I created a unity package of the project and put a link to it in the description. You will need to make sure you install cinemachine and the input system package to get it to work right.
Jump is not working after I pressed Space button it didn't work??
The easiest way to fix it is to walk through each part and check it. I would start by making sure your input action is set up correctly. Then make sure you have connected the jump method to the jump action on the player input manager. If both of those are correct, then it is likely something wrong with the jump function. If it is a problem with code, I will need to know more to help.
@@sodarocketstudios Thanks of the reply, but I have corrected it on the moment 😊
Hi. I followed your tutorial until 8:31 but when I press the play button, it isn't my character that is moving but the camera itself. How to fix this? My camera is the one that is moving not the character.
Did you attach the avatar controller script to the player instead of the camera?
@@sodarocketstudios yes on the player. I attached it on the player. I just followed your instructions
@@kurtlosbanos6123 I'm not sure how that happens since I use a character controller to move the character. Unless your character is a child object of the camera, but then both would be moving. are your character and camera two completely separate game objects?
@@sodarocketstudios Yes they are separate. I would like to send you a picture but I don't know how and I cant comment pictures in youtube.
can i have that script it is hard to type pls
I will put it up when I get a chance. Unfortunately I won't have access to the computer with the files for awhile.
@Soda Rocket Studios can you add video for third-person shooting controlling guns and animations.
I can definitely start looking into it. I might do something a bit less specific to try and keep it useful for more people.
This is just a guess, but I suspect that for something like guns, instead of making character animations for each specific gun, you could put target points on the gun and use inverse kinematics (I'm not an expert at animation, so this could be very wrong.). I played with that a tiny bit when I was making the Mixamo video. I can start researching, and, if it looks like an approach that makes sense, I can make a video explaining how to do it. If I covered third-person shooter controls, I might make it it's own video. Were you thinking things like how to aim and setup a crosshair, then how to determine what the player is shooting?
@@sodarocketstudios thank you so much. Yes i was thinking about aim and shooting.
I might try to do a video on the controls portion first. I think I would be able to get it out faster. I definetly recommend doing some research on it in the meantime if you need it soon.
Sure i will do some research.
Can you please continue this tutorial to add a shift sprint and make this bit smooth
To add sprinting, you just need to change the movement speed when the sprint key is pressed.
@@sodarocketstudios what if statement where do a GetKeyDown press shift = increase the speed of the player and play the sprinting animation
Will that work?
With how I setup the control script, I think the easiest way would be to add in a sprint input action. Then in the player controller script add an OnSprint function just like all of the other controls. In that function you will want to check the phase of the sprint button. If the phase is started(meaning the button was pressed) you can multiply the movement speed by some sprint speed multiplier. If the phase is canceled (meaning the button was released) you can then divide my that speed multiplier.
So you will have:
If(context.started)
MovementSpeed*=sprintMultiplier
If(context.canceled)
MovementSpeed/=sprintMultiplier
@@sodarocketstudios is it possible that I can share my updated script with you on Twitter or something so that you can look into it , and if you can also tell me what could I change in animator window with sprint animation
On Twitter I am @SodaRocketDev. Or if you go to my channel, you can get my email (I don't want to put it in a comment to avoid bots). As for the animation part, I haven't done too much with animations so I can't tell you exactly what to do, but I can point you toward blend trees. I know there are several tutorials on them, and I think that might be what you are looking for.
Extra code for rotation? Using A and D from wasd
instead of the mouse delta.x being added to the rotation vector, add the x component of the move input vector multiplied by some rotation speed value. I believe that will work. I am in a game jam right now, but If you need more help, I can try some things after this week.
@@sodarocketstudios Yeah I am pretty stuck so I would love getting more help once you are free if that is possible
@@vinesseyt The quick and dirty way you can accomplish this is to comment out ReadValue in the OnLook method, then in On move, change
moveVector = context.ReadValue();
to
moveVector.y = context.ReadValue().y;
and right after that, add
lookVector.x = context.ReadValue().x;
Instead of telling the character to walk left or right, you are now telling the camera to rotate based on the A and D input. It will be very slow, so you may need to increase the sensitivity multiplier when setting the rotation.
jump dont works for me
In what way does it not work? I can try to walk through it with you.
Hi, I didn't find that Input Actions?? Can anyone help me??
i know its a bit late but you need to install the input system package, package manager -> unity registry -> input system
how would you do this for first person?
The easiest way would be to create an empty game object under the character hierarchy. You will put this object where you want the eyes to be. then set the camera (Not a cinemachine virtual camera) as a child of the eyes object and set the position as (0,0,0).
@@sodarocketstudios thank you!
@@sodarocketstudios this works great, but the player starts to randomly move around unless you move forward and I'm not sure how to make it so you can look left and right
@@BenGodot When you say it randomly moves, is it just walking on its own, or more like sliding? If it is walking around, then the only problem I can think of is that the motion vector isn't getting zeroed properly when you release the movement buttons.
Looking left and right should be handled with the rotate method we created that will rotate the character around the y-axis. I am realizing now, that if you converted this controller to first person, then you wouldn't be able to look up and down, so you would need to add that by rotating the camera around its local x-axis based on the y value from the mouse delta.
If you set it up to look up and down, but not left and right, then you want to rotate the character on the y-axis using the x component of the delta, and rotate the camera on its x-axis based on the y component of the mouse delta.
@@sodarocketstudios thank you!
25:59
isnt working no clue what i did wrong
followed all steps character wont move
What part isn't working? It's possible that I had a mistake in the video, or something changed between different versions of unity. You aren't the only that seems to be having problems, so it might help others if we can work through it.
@@sodarocketstudios im on unity 2021 so maybe thats why but i found a third person controller pack in the unity asset store so im using that now
pls put it in dicreption
18:18
20:57