# How to have an object stop incrementing speed after a certain value?,

So I’m playing around with making a simple Pong game (with tutorials), and am trying to have it so the ball doesn’t move any faster after a certain point (it gets a bit faster each time it hits a paddle). Because if it moves too fast it just goes right through the paddles. I had wanted to add a couple extra features to make it my own even though I’m still new with coding.

Any help is greatly appreciated!

``````public class Ball : MonoBehaviour
{
public float speed = 200.0f;
private Rigidbody2D _rigidbody;

private void Awake()
{
_rigidbody = GetComponent<Rigidbody2D>();
}

private void Start ()
{
resetPosition();
}

public void resetPosition()
{
_rigidbody.position = Vector2.zero;
_rigidbody.velocity = Vector2.zero;
}

{
float x = Random.value < 0.5f ? -1.0f : 1.0f;
float y = Random.value < 0.5f ? Random.Range(-1.0f, -0.5f) : Random.Range(0.5f, 1.0f);

Vector2 direction = new Vector2(x, y);
}

{
}

}
``````

Apologies, I have done some testing and found my mistake.

On the ball use this

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball : MonoBehaviour
{

public float moveSpeed = 1f;
public float maxSpeed = 4;

Rigidbody rb;

void Start()
{
rb = GetComponent<Rigidbody>();
Move();
}

void Move()
{
}

private void Update()
{
Debug.Log(rb.velocity.magnitude);

if(rb.velocity.magnitude > maxSpeed)
{
rb.velocity = rb.velocity.normalized * maxSpeed;
}

}
}
``````

Then on each of the paddles use this:

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

{

Rigidbody rb;
public float force = 50f;

void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Ball") // Do not forget assign tag to the field
{
rb = col.gameObject.GetComponent<Rigidbody>();