projectile max speed

Hello!, this will be my first question on here! wohoo.

Basically I’m making a game like angry birds, I need to know the top speed of the projectile that is being thrown. I have it’s current velocity.magnitude but how do I gather up all the floats and find the max? I tries using this

Debug.Log ("speed: " + Mathf.Max(speed));

but that’s only printing the current speed every frame (I think)


Hello there,
You can try this code, it will be something similar to this:

    public float maxSpeed; //Maximum speed
    public float minSpeed; //Minimum speed
    public Rigidbody bird; //The object that you will throw
    void Update() {
		bird.velocity = new Vector3(Mathf.Clamp(bird.velocity.x,minSpeed, maxSpeed),
		                            Mathf.Clamp(bird.velocity.y,minSpeed, maxSpeed),
		                            Mathf.Clamp(bird.velocity.z,minSpeed, maxSpeed));

Omar Balfaqih

Hi Hathakas,
if I well understood you want to know the maximum speed that your projectile can have? Usually it’s up to you how fast it can go, so you would have a variable that already has that information which you would use to set the limit beyond which the speed cannot go.

Anyway, assuming you really have a projectile whose max speed has to be determined in real time, this is how you should do:

  • First of all declare a variable called maxSpeed in your class

    float maxSpeed = 0f;

  • Then for every frame you check if the current speed is greater than the previous one.

    void Update()

    // …code here…

    currentSpeed = rigidbody.velocity.magnitude;

    if(currentSpeed > maxSpeed)
    maxSpeed = currentSpeed;


By doing so you’ll always have the maximum speed that your object reached SO FAR.

Hope it helps.