Hi I’m trying to smooth the movement of a ball on a 2d plane. Here is the code. It works fairly well but It’s not reactive as i need:
void Update () {
//float moveInput = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
speed = Input.acceleration.sqrMagnitude;
newSpeed = Mathf.Lerp(speed, newSpeed , Time.deltaTime * 10 );
float Move = Input.acceleration.y * newSpeed;
speed = newSpeed;
transform.position += new Vector3(Move, 0, 0);
Debug.Log(Time.deltaTime);
float max = 14.0f;
if (transform.position.x <= -max || transform.position.x >= max)
{
float xPos = Mathf.Clamp(transform.position.x, -max, max); //Clamp between min -5 and max 5
transform.position = new Vector3(xPos, transform.position.y, transform.position.z);
}
}
Ps. If you have good books on Physics for games please feel free to post the titles, so I won’t bother with this questions anymore