Accelerate an object without a rigidbody

Hello,

I need to accelerate an object, but it can’t have a rigidbody (it’s supposed to be rigidly attached to a rigidbody and fixedjoint is garbage).

For now I want it to accelerate downwards at 9.81 m/s2. I’ve tried this :

float a = 9.81f;
float v;

void FixedUpdate() {
    v += a / Time.fixedDeltaTime;
    transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y - v / Time.fixedDeltaTime, transform.localPosition.z);
}

But the object drops way too fast. Do you know how I should implement it?

I’m not an expert in physics or anything, but just a quick calculation for sanity checks shows this is going to be really wrong. Time.fixedDeltaTime is pretty much constant at like .02f I think (50 updates/second), and dividing by .02f means multiplying by 50. “a” is an acceleration, meters/s/s, and fixedDeltaTime is an interval, updates/s. You should probably be multiplying instead.

3 Likes

Thanks, it looks like it works correctly now !