input.getaxis problem
I have a pet follow script where the pet follows the player. I need the pet to flip when the player changes direction so I wrote this.
public class PetFollow : MonoBehaviour
{
public float speed;
public float stop;
private bool FacingRight;
private Transform target;
// Start is called before the first frame update
void Start()
{
FacingRight = true;
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxis("Horizontal");
flip(horizontal);
if (Vector2.Distance(transform.position, target.position) > stop)
{
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
}
private void flip(float horizontal)
{
if (horizontal > 0 && !FacingRight || horizontal < 0 && FacingRight)
{
FacingRight = !FacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
Debug.Log("fliped?");
}
}
}
for some reason the "Horizontal" isn't changing from 0 so the flip is never called, and I have no idea why
Comment