I wrote a simple character movement script but for some reason when the character starts moving they slide slowly across the map. I’m not new to programming but I am new to C# so I’m unsure if there is something I am missing in my code. Any help would be greatly appreciated!
[SerializeField] private string horizontalInputName;
[SerializeField] private string verticalInputName;
[SerializeField] private float movementSpeed;
private bool isMoving = false;
private CharacterController chardController;
private void PlayerMovement(){
if (((Input.GetAxisRaw(horizontalInputName)) != 0) || ((Input.GetAxisRaw(verticalInputName)) != 0))
{
isMoving = true;
Debug.Log ("is moving");
}
else
{
isMoving = false;
Debug.Log ("is not moving");
}
if (isMoving)
{
float horizInput = Input.GetAxisRaw (horizontalInputName) * movementSpeed;
float vertInput = Input.GetAxisRaw (verticalInputName) * movementSpeed;
Vector3 forwardMovement = transform.forward * vertInput;
Vector3 rightMovement = transform.right * horizInput;
chardController.SimpleMove (forwardMovement + rightMovement);
}
else
{
chardController.gameObject.transform.position = Vector3.zero;
}
JumpInput ();
SprintInput ();
}