pretty self explanatory title but lets expand a little so i now have a few UI buttons left right and jump but my players left and right motion is controlled through Input.GetAxis("Horizontal")
so im wondering if i can split this somehow into left and right this is the block
moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(moveHorizontal, 0, 0);
rb.AddForce(movement * speed);
so i need to check if moveHorizontal is < or > 0 and then move left or right but i dont know how you can move left or right using getAxis or if i can swap it to something like getKey and still keep the same speed and such, heres how im passing the code to my UI button, someone from here helped me with this,
public void Move(string mDir)
{
if (mDir == "left")
{
moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(moveHorizontal, 0, 0);
rb.AddForce(movement * speed);
animator.SetFloat("rollLeft", 0);
animator.SetFloat("rollRight", 2);
jumpingDirection = false;
if (moveHorizontal < 0)
{
}
}
else if (mDir == "right")
{
moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(moveHorizontal, 0, 0);
rb.AddForce(movement * speed);
animator.SetFloat("rollRight", 0);
animator.SetFloat("rollLeft", 2);
jumpingDirection = true;
if (moveHorizontal > 0)
{
}
}
else if (mDir == "jump")
{
doMovement = true;
isGrounded = false;
rb.AddForce(0, jumpSpeed, 0);
source.PlayOneShot(jumpNoise, 1f);
if (jumpingDirection == true)
{
animator.SetFloat("jumpLeft", 0);
animator.SetFloat("jumpRight", 2);
}
else if (jumpingDirection == false)
{
animator.SetFloat("jumpRight", 0);
animator.SetFloat("jumpLeft", 2);
}
}
so obviously as it stands left and right do nothing but change the animation and that works but theres obviously no movement but jump works fine
any and all feedback welcome