Hello, I am relatively new to unity and I have made a physics based character controller using rb.MovePosition. When I go left, it works, but when I go right, it doesn’t move. There are no compiler errors and the rest of the game runs normally. Can someone help? Here is my code:
void Update()
{
rb.MovePosition(transform.position + input * Time.deltaTime);
if (Input.GetButtonDown("Left"))
{
input = new Vector3((Input.GetAxis("Horizontal") - 10) , 0, (Input.GetAxis("Vertical")));
}
if (Input.GetButtonDown("Right"))
{
input = new Vector3((Input.GetAxis("Horizontal") + 10) , 0, (Input.GetAxis("Vertical")));
}
if (!Input.GetButtonDown("Left") && Input.GetButtonDown("Right"))
{
input = new Vector3(0, 0, 0);
}
If there are any optimisations I could do to this code, let me know.,Hello, I am relatively new to unity, and i have created a physics based character controller using rb.MovePosition. When I go left, it works, but when I go right, the character doesn’t move. There are no compiler errors appearing and I can play the game normally. Can someone help? Here is the code:
void Update()
{
rb.MovePosition(transform.position + input * Time.deltaTime);
if (Input.GetButtonDown("Left"))
{
input = new Vector3((Input.GetAxis("Horizontal") - 10) , 0, (Input.GetAxis("Vertical")));
}
if (Input.GetButtonDown("Right"))
{
input = new Vector3((Input.GetAxis("Horizontal") + 10) , 0, (Input.GetAxis("Vertical")));
}
if (!Input.GetButtonDown("Left") && Input.GetButtonDown("Right"))
{
input = new Vector3(0, 0, 0);
}
If there are any optimizations I could do to this code, you can let me know too.