- Home /
Adapting Horizontal and Vertical movement to New Input System?
public class ThirdPerson : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmooth = 0.5f;
private float turnSmoothVel;
private int Playernum;
// Update is called once per frame
void Update()
{
float hortizonal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(hortizonal, 0, vertical).normalized;
if(direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVel, turnSmooth);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
Hey all! So I've been looking to adapt my input system to the new version unity has added. I just cannot for the life of me figure out how to adapt an input for the new system. Using "Horizontal" and "Vertical" axis for movement in my code. Of course I could just delete it all and add the simple version the new system allows, but I have a movement looking and dampening script. Shown above.
I'm not really sure how to tackle this from how new the system is and i'm really struggling wrapping my brain around it. From my understanding it will involve a 1 axis with a negative and positive value for horizontal and vertical on a gamepad or keyboard. But i'm really not sure how to translate that into code with what I have. Any ideas on how to adapt this code for the new system or will I have to suck it up and re imagine this look dampening code?
Your answer
![](https://koobas.hobune.stream/wayback/20220613004322im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play animation for horizontal and vertical movement? 1 Answer
Make movement vertically,How to move Vertically? 1 Answer
How can I make GUI button send an input message when I press it? 0 Answers
How can I play different animations depending on the direction my character is moving? 1 Answer
changing a float number by moving arrows (horizontal and vertical input)? 1 Answer