Cannot limit velocity when using tilt acceleration

Hey guys,

I am using following script to move my Player by tilting the phone:

 void FixedUpdate ()
        {
			
	
			tiltAcceleration = Vector3.zero;

			tiltAcceleration.x = Input.acceleration.x;
			if (tiltAcceleration.sqrMagnitude > 1)
				tiltAcceleration.Normalize();
			
			tiltAcceleration *= Time.deltaTime;

			transform.Translate (tiltAcceleration * sideSpeed);

                    // This is how I try to limit my velocity of Player, but it DOES NOT WORK!
			playerRigidbody.velocity = Vector3.ClampMagnitude (playerRigidbody.velocity, 5f);


        }

In the code above, you can see at the last line, how I am tryint to limit my velocity while tilting the phone - however, this does not work, it still moves too fast, so it passes the Box Colliders (side-walls).

I have read few answers here on Unity, but noone helped in my case.

Any advice appreciated.

As you’re setting the position of the object yourself ( with transform.Translate ), the velocity property is not used. What you need to limit is the value of (tiltAcceleration * sideSpeed)

However, if you’re using physics - and it looks that you are - you shouldn’t translate an object directly, instead use AddForce() to apply a force in the direction of the tilt.