- Home /
How to rotate character on horizontal inputs while moving forward?
Left side movement is how it moves. I need the character to move like the one on the Right side. It might be basic but I'm pretty new to coding. Thank you.
Basic movement script used:
public Rigidbody rigidbody;
private CharacterController controller;
public float forwardSpeed = 5;
public float maxSpeed = 10;
private float horizontalInput;
public float horizontalSpeed = 10;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
}
void FixedUpdate()
{
Vector3 forwardMove = transform.forward * forwardSpeed *
Time.deltaTime;
Vector3 horizontalMove = transform.right * horizontalInput * Time.deltaTime *
horizontalSpeed;
rigidbody.MovePosition(rigidbody.position + forwardMove + horizontalMove);
}
Answer by Qdevesh · Oct 10, 2021 at 05:49 PM
@elproue I have not able to understand your question please more clearify what you want to know about And i am also new to code 1.5 year later and this also happens with me
There's that object at bottom. By using the above code, the object is moved horizontally by Inputs on X-axis while it is moving forward. And the movement is like sliding. What I want to know is how to move the object horizontally while having a little Y-axis rotation. Like make the object face the direction it is moving to.
Your answer
![](https://koobas.hobune.stream/wayback/20220613044026im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character to Ground and Turn Rotation 1 Answer
Character rotating on supposedly locked axis 2 Answers
Need help rotating multiple paths on an axis 0 Answers
How to Prevent Character Bouncing 0 Answers