- Home /
Unity input system character control
Hi so im new to codeing and want to make a 2D platformer and im struggleing with the new unity inpud system i know ho to make the input actin map but i dont know how to make the script for it. Can someone help me please this is my input action map:
btww my input action is called Controls
Answer by Razputin · May 07, 2021 at 06:14 PM
Here's one way to do it...
Set your Player Input component Behaviour to "Invoke Unity Events"
Create a method for retrieving the incoming values, here's mine I use. Movedirection is what ends up getting passed into my RigidBody.
public void OnMovement(InputAction.CallbackContext value)
{
m = value.ReadValue<Vector2>();
//y is actually going to go into z
//i'm just setting x / y to 0 if the input is less than .1 because that means we're barely touching the input and we probably dont intent to actually move.
if (m.x < .1f && m.x > -.1f)
{
m.x = 0;
}
if (m.y < .1f && m.y > -.1f)
{
m.y = 0;
}
//assign the values into a vector3 that I use for movement
moveDirection = new Vector3
{
x = m.x,
y = 0.0f,
z = m.y
};
}
Assign the Method in player inputs by expanding Events -> Controls(Your input action map name) -> Dropping your script with the below method into the Move field. (See pic below.)
![alt text][1]
[1]: /storage/temp/180423-azzzz.png
hi i konw thet you dont want to do it but can you explain it to me i dont want to be just copy and paste guy. So please explain it for me
https://www.youtube.com/watch?v=5tOOstXaIKE&ab_channel=Unity
Watch this, it's where I learned how to use the new input system and will explain it far better than I can. It's also an official tutorial and only ~10$$anonymous$$.
hi i watched the video but i dont know what to put to the object in the events the guy puts there a player controler script (time in video 6:40) but i dont have any player contoler i try to set one but it didn't turn out well can you help me?
Your answer
Follow this Question
Related Questions
Unbinding in game settings 1 Answer
My click to move to script moves instantly instead of steadily 1 Answer
Jumping is randomly not working. 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers