Calculate position based on acceleration (gravity)

Hello.
I’m new at Unreal Engine, so I may ask stupid things. Please be patient :slight_smile:
I have an object in game, which should have physics disabled but should fall down. So in tick() function I’m simulating gravity.
I’m using following simple formulas and gravity constant:
g = 980 cm/s;
g = dV/dT => dV = 980 * dT;
dS = V * dT
So, my tick function looks like
void ABasePowerup::Tick(float DeltaTime) {
CurrentFallingSpeed += -980 * DeltaTime;
AddActorLocalOffset({0.0, 0.0, CurrentFallingSpeed * DeltaTime});
}
default value for CurrentFallingSpeed is 0.

I apply this code to cube, for which I disabled gravity and physics simulation. Next to that cube I put another cube with physics simulation and gravity enabled. Result is quite confusing - calculations above give higher speed that UE’s simulation.
Question: what’s wrong with code or formulas that I’m using? How to get the same results as UE’s simulation (with physics disabled)?

Interesting observations:

  1. In general, object, controlled by my calculations, moves quite naturally. If I would not compare it with UE’s simulated results, I would probably not even notice that there is a mistake
  2. After the very start of simulation, all objects, for which UE simulates physics, look like stuck for a moment. They not stack, of course, but kind of moving slowlier that I would expect in real life. At the same time object, controlled by my calculations, immediately moves quite fast (which looks more natural). This makes me think that probably physics simulation in UE starts with delay? I’m 99% sure I’m wrong in this statement, just need someone to confirm :slight_smile:
2 Likes

At default settings the physically simulated Static Mesh Components have Linear Dampening of .01 - it may not seem like a lot, but zero it to see if you get more consistent results. Also, if Tick is supposed to sim physics (not an unusual thing to do), you may need to:

Otherwise you’d be getting fake sim an unfair advantage :wink:

2 Likes

Hi @Everynone. Thanks for such a fast answer!
I zeroed Linear Dampening, but nothing seems to change. Also I checked Tick Group of object, where I simulate gravity, and it was already set to “During Physics”.

1 Like

One even more interesting observation. I set 2 cubes on height 800 cm and let them fall down. One was driven by default physics simulation, another by custom one, described higher. On certain level I printed time, spent starting from simulation (= time of falling). Lineal damping is off for both cubes. Based on formula s = V0*t + (a * t^2)/2 => a = (2 * s) / t^2 I made this table
image

Observations:

  1. Custom simulation gives more precise results (how can it be?)
  2. The longer distance, the less error (that’s expected)
  3. Looks like engine starts physics simulation with delay, which results in nearly constant delay (0.4 sec) between cubes driven by default and custom simulation, despite of distance they passed.

I still don’t believe gravity simulation in UE is so inaccurate. I think something is wrong with my formulas/way of simulation/test. Can anyone find the reason why results are different and why?

1 Like

Problem solved?

Actually not. I still don’t have an answer on question - is gravity simulation in UE is so inaccurate or I made mistake in the way I made my measurements.