Speed doubles using RotateAround()

Hello everyone,

So, I am trying to move a box on a curve as it is being moved by the curve itself. For that I am using RotateAround() on the OnTriggerStay() event of the curve. I know the speed of the curve in meters per second, but I don’t know its length neither its speed in degrees per second to use on RotateAround(). Since the curve is an arc of a circumference with 2.55 meters of radius and I also know its angle, I am able to find its length in order to calculate the speed in degrees per second. For that I am using the following code:

public void SetSpeed(float speed) 
{
    float radius = 2.55f;
    //First find the curve length
    float length = Mathf.Abs(2 * Mathf.PI * radius * angle / 360);
    //Then calculate the time the box will be moving on the curve
    float time = length / speed;
    //Finally, the speed in degrees per second instead of meters per second
    degreesPerSecond = angle / time; //angle is a global field
}

And my curve OnTriggerStay() looks pretty much like this:

public void OnTriggerStay(Collider other) 
{
    Box box = other.GetComponent<Box>();
    if (box == null) return;
    //ChangeCurve() only changes currentCurve on the box if it has got out of the last curve
    box.ChangeCurve(name);
    if (name != box.currentCurve) return;
    //rotated around is correctly positioned on the center of the circumference
    box.transform.RotateAround(rotateAround.position, Vector3.up, degreesPerSecond * Time.fixedDeltaTime);
}

The problem is that the box moves with double the speed which it should. But I have checked, and my math is right. For example, for a 45º angle and a speed of 2.5m/s it calculates around 56.17234 degrees per second which makes sense since that for a 45º angle the curve should have a little more than 2 meters. I have also thought on the box being moved by 2 curves on the same time but ChangeCurve() is working fine. Had similar problem with straights before and the fix was implementing this method that only let’s change the currentCurve after the OnTriggerExit() of the curve. So, I don’t understand where my mistake is… Hope you guys can help me :slight_smile:

Iirc then

 Time.fixedDeltaTime 

will always be 0.02 seconds unless set otherwise in the physics settings.

This is not the correct value here i think. Please try using

 Time.deltaTime 

instead. This is usually a lower value - depending on your framerate so would result in a slower movement