whenever I move moveHorizontal is always 0 how can I change this?
//setting up variables
private Rigidbody2D rb2D;
private float moveSpeed;
private float jumpForce;
private bool isJumping;
private float moveHorizontal;
private float moveVertical;
void Start()
{
//defining variables
rb2D = gameObject.GetComponent<Rigidbody2D>();
moveSpeed = 3000000f;
jumpForce = 60f;
isJumping = false;
}
void Update()
{ //input for left right movement
float moveHorizontal = Input.GetAxisRaw("Horizontal");
moveVertical = Input.GetAxisRaw("Vertical");
Debug.Log("moveHorizontal " + moveHorizontal);
Debug.Log("Velocity " + rb2D.velocity.x + " " + rb2D.velocity.y);
}
void Addforce()
{
//function that adds a force to rigidbody
rb2D.AddForce(new Vector2( moveHorizontal * moveSpeed, 0f), ForceMode2D.Impulse);
}
private void FixedUpdate()
{
if (moveHorizontal > 0.1f || moveHorizontal < -0.1f)
// if moveHorizontal is greater then 0.1f or if moveHorizontal is less than -0.1f then put a force to a rigidbody
{
Addforce();
}
}
