I’m trying to get an object to accelerate along the x axis, and this is working for the most part but it doesn’t pick up the input half the time, and so the variable won’t switch causing the object to shoot off in one direction.
public class paddle_move : MonoBehaviour {
public float xaccel;
private float acceltotal = 0;
void Update () {
acceltotal += xaccel;
rigidbody2D. = rigidbody2D.velocity + new Vector2 (acceltotal, 0.0f);
if (Input.anyKey) {
xaccel *= -1;
}
}
}