Jump to content

Physics Warp - How Does Time Step Work


Recommended Posts

This is something that has confused me for a long time: if you have a simple spaceplane with two jet engines mounted at the wingtips, entering physics-warp will bend the wings forward. This implies that the thrusts (and therefore torques) are simply increased, rather than actually changing the value of the time step used in physics calculations. What is going on?

Link to comment
Share on other sites

It's about how the simulation works. If you have an engine that pulls your rocket somewhere, the physics engine applies thrust on the engine directly (by moving it slightly forward), and on the rest of the ship indirectly, i.e. through resolving displacements on individual joints within the ship structure. If you increase time step, the displacement added directly to the engine position grows.

Link to comment
Share on other sites

It's about how the simulation works. If you have an engine that pulls your rocket somewhere, the physics engine applies thrust on the engine directly (by moving it slightly forward), and on the rest of the ship indirectly, i.e. through resolving displacements on individual joints within the ship structure. If you increase time step, the displacement added directly to the engine position grows.

I assume the way displacements apply force is by modeling joints as linear springs. This, however, has nothing to do with changing the time step. The force applied is constant with time step; the displacement should be constant too.

Or are you suggesting that there is no "time-step" used in Unity/PhysX at all; the time step is merely simulated in KSP. This would explain why my intake air multiplies by a factor of 4 when i enter 4x time warp (the air flowrate in kg/s should remain constant with time step).

Do you have any references for what you are saying? I am interested in learning more.

Link to comment
Share on other sites

I assume the way displacements apply force is by modeling joints as linear springs.

That seems reasonable.

The force applied is constant with time step; the displacement should be constant too.

My understanding is that force stays the same but by acting for four times longer it delivers four times the work. Subsequently it causes four times the displacement.

There may also be positive feedback - as joints bend, engines are no longer parallel and their force vectors increase the bending.

Edited by Kasuha
Link to comment
Share on other sites

Shouldn't this be in the question part of the forum? Not suggestions and development?

Maybe, but its labelled as discussion, and it seems to me this is an artifact of the way KSP treats time steps, hence a suggestion to fix it.

Link to comment
Share on other sites

What seems to happen is:

- The impulse is applyed to the engine.

- Joint resolution move the ship forward.

So far so good, that is how physic usually to work.

BUT, when you warp, the simulation step is increased, so the joint diverge much more before resolution kicks in. That is why the vessels bend in bizare way when time is warped.

Link to comment
Share on other sites

What seems to happen is:

- The impulse is applyed to the engine.

- Joint resolution move the ship forward.

So far so good, that is how physic usually to work.

BUT, when you warp, the simulation step is increased, so the joint diverge much more before resolution kicks in. That is why the vessels bend in bizare way when time is warped.

This doesnt make sense to me. If joints are modeled as linear springs, then displacement is related to force, and force is constant regardless of time warp...

m*dV/dt = F

If dt becomes larger, then dV becomes larger for constant F (and m)

Link to comment
Share on other sites

It could quite simply be a matter of while forces of thrust are being scaled (by the larger delta), the various resistance forces are not, heh.

(I generally avoid using variable deltas in my own work, partly because of lazy, partly because I don't have to worry about the above)

Link to comment
Share on other sites

I`ve always wondered why the forces are not divided by four when time is multiplied by four. If the time step is four times larger then that suggests a quarter strength force would balance out by being applied for `longer`.

There MUST be a way to not have excessive physics warp destroy your ship. Seems like it has not been well thought out. It`s just maths after all.

You could just do a quick test to see if the engines would destroy the craft at near dry weight and full thrust then if that won`t happen then thrust under rails...

Link to comment
Share on other sites

There MUST be a way to not have excessive physics warp destroy your ship. Seems like it has not been well thought out. It`s just maths after all.

I agree with you. The physics warp code hasn't been touched for a long time in KSP - maybe now it needs an upgrade. Of course, maybe it's a lot harder to deal with than I thought.

I also thought I'd bring up the BetterTimeWarp mod into this discussion. It allows you to have as much physics warp as you could ever want - a billion times normal speed if you so desire. If you use it on 10,000x speed and you're burning an ion-powered probe, logic tells me that the ship should disintegrate from the increased forces (Just think about how much more force is applied in 4x warp than 3x warp). And yet, that's not what happens. So... I wonder if that says anything (I'm just a layperson, so I won't/can't jump to any technical conclusions).

Link to comment
Share on other sites

My understanding is that force stays the same but by acting for four times longer it delivers four times the work. Subsequently it causes four times the displacement.

It would be good to have some inputs directly from Harvester or someone who knows the true answer, because guesspeculating is not good.

What I don't understand is TW should be seen as time step modification, as to be very very simple:

(for current frame)

physics[t] = something_like_get_previous_state(physics[t-1]) + forces_actually_at_work[t]
display_frame(t)

with t = the time step.

using timewarp should make t=t+1 become t=t+TW (+2/3/4 for stock atmo warp) with a bit of code to interpolate forces between skip frames

(if you have z= +50 kN, every frame, thurst for TW2 = 100 kN for frame 1 to frame 3, with TW2 = 2x timewarp) + all the related calculations.

Considering the basic game loop may be:

while (1)
{
do calculations
manage vsync (=wait if needed)
display frame
}

Then, "bizarre" forces and SAS misbehaviour should not happened, but it's not actually the case, all parts joints that could bend (typically wing connectors) bend and SAS is unable to work properly (if we can consider it's even work properly as it's very dumb most of the time but that's another topic)

Edited by Justin Kerbice
Link to comment
Share on other sites

It could quite simply be a matter of while forces of thrust are being scaled (by the larger delta), the various resistance forces are not, heh.

(I generally avoid using variable deltas in my own work, partly because of lazy, partly because I don't have to worry about the above)

Force of thrust should not be scaled with time-step.

Link to comment
Share on other sites

It would be good to have some inputs directly from Harvester or someone who knows the true answer, because guesspeculating is not good.

What I don't understand is TW should be seen as time step modification, as to be very very simple:

(for current frame)

physics[t] = something_like_get_previous_state(physics[t-1]) + forces_actually_at_work[t]
display_frame(t)

with t = the time step.

F ... thrust force

m ... mass of the engine

a ... acceleration

t ... time

v ... speed

s ... position

ds, dv, dt ... changes in position, speed, time. dt is a parameter here

Newton physics:

a = F / m

dv = a . dt

ds = a . dt^2 / 2 + v . dt

if dt = 1, then ds = a / 2 + v

if dt = 4, then ds = 8 . a + 4 . v

As you can see, the force / acceleration-releated part of displacement grows with square of dt, not linearly with it.

Only after moving the engine by ds, the action of joints is applied to it, pulling it back somewhat and pulling the rest of the ship along the engine. Doing it differently would require solving really complicated set of differential equations. I'm pretty sure that's not how PhysX works.

So yeah, this is all guesses. But I believe I am not very far from truth.

Link to comment
Share on other sites

Joints are not just linear springs, they can rotate as well. That's how rockets can wobble/bend.

They are linear with distance and linear with rotation. There is such a thing as a linear torsional springs as well... This is accounted for in the stiffness tensor.

Link to comment
Share on other sites

I`ve always wondered why the forces are not divided by four when time is multiplied by four. If the time step is four times larger then that suggests a quarter strength force would balance out by being applied for `longer`.

There MUST be a way to not have excessive physics warp destroy your ship. Seems like it has not been well thought out. It`s just maths after all.

You could just do a quick test to see if the engines would destroy the craft at near dry weight and full thrust then if that won`t happen then thrust under rails...

This is why you cant think about math .... without math. :cool:

Increasing time step does not change the forces, it just changes the deltaV over that time step. The fact that it messes with forces/torques/displacements implies the time step is not really a physics time-step.

Link to comment
Share on other sites

F ... thrust force

m ... mass of the engine

a ... acceleration

t ... time

v ... speed

s ... position

ds, dv, dt ... changes in position, speed, time. dt is a parameter here

Newton physics:

a = F / m

dv = a . dt

ds = a . dt^2 / 2 + v . dt

if dt = 1, then ds = a / 2 + v

if dt = 4, then ds = 8 . a + 4 . v

As you can see, the force / acceleration-releated part of displacement grows with square of dt, not linearly with it.

Only after moving the engine by ds, the action of joints is applied to it, pulling it back somewhat and pulling the rest of the ship along the engine. Doing it differently would require solving really complicated set of differential equations. I'm pretty sure that's not how PhysX works.

So yeah, this is all guesses. But I believe I am not very far from truth.

THANK YOU! I think that makes a lot of sense and explains it. What you are saying is the PhysX engine applies physics directly to the parts with thrust and integrates the equations of motion for each part, causing the engines to displace farther and pull on the ship to accelerate it.

What would be smarter/better is to treat the ship as a rigid body for the purpose of conserving overall linear and angular momentum, and then resolve all forces/torques between all parts in the rigid body. i.e. instead of treating each parts displacement on an absolute scale (with no realization that the parts of the ship are connected), treat the ship as a whole on an absolute scale and then each individual part locally. Unfortunately, if this is true, there is no way to change this without changing PhysX itself.

Maybe i should make my own engine?

Edit: I think this is a direct result of performing explicit integration rather than implicit. If implicit integration were used, the parts undergoing thrust would not displace as much, because the external forces on the part would be calculated implicitly i.e. based on the future displacement (rather than the present displacement i.e. explicit).

Edited by arkie87
Link to comment
Share on other sites

I don't know about the code or maths involved, but I wonder if a simple fix could be to "freeze" the spacecraft if it's stable enough. Specially so in space, where there aren't aerodynamic forces (ok, well). Basically, before entering physics warp, the game calculates if maneuvers like throttling up or gently turning the ship can cause it to break or bend above a certain threshold. If it doesn't, the parts are kind of "welded" together until the ship exits physics warp or the player does a more extreme maneuver

Link to comment
Share on other sites

I don't know about the code or maths involved, but I wonder if a simple fix could be to "freeze" the spacecraft if it's stable enough. Specially so in space, where there aren't aerodynamic forces (ok, well). Basically, before entering physics warp, the game calculates if maneuvers like throttling up or gently turning the ship can cause it to break or bend above a certain threshold. If it doesn't, the parts are kind of "welded" together until the ship exits physics warp or the player does a more extreme maneuver

I think this is exactly what i was saying above: you basically treat the ship as one part to conserve momentum. And afterwards, you calculate forces and torques on parts to see if they break. This will make the physics and physics warp a lot more stable. Unfortunately, it seems like PhysX is in control here and for the sake of generality, solves the physics for each part separately and then applies forces between parts.

However, i suppose its still possible to fix it, by telling PhysX the ship is a rigid body and calculating stresses and displacements manually afterward.

Link to comment
Share on other sites

This doesnt make sense to me. If joints are modeled as linear springs, then displacement is related to force, and force is constant regardless of time warp...

m*dV/dt = F

If dt becomes larger, then dV becomes larger for constant F (and m)

It is not that simple. Because your ship is made of many parts and joints, and you simulate by step (like any physic engine do). You cannot know ahead of time what joint force to apply, as the force will depend on the divergence between the part of the ship. To make thing worse, each joint force change the behavior of other joints. You typically have 2 way to simulate joins (and all composition of these on various translation and rotation axes to for rail-like joints for instance):

- solid joints, where the 2 bodies are simulated as one, and a computation is done to know if the joint broke (in which case the engine switch to simulate the 2 bodies independently).

- dynamic joints, where the various bodies are simulated as if no joint existed, THEN a joint resolution engine kicks and try to make the whole thing converge to some realistic solution using the joints.

The dynamic joints are way more complex to simulate (it is especially hard to ensure that the joint resolution step will converge to some solution in a reasonable amount of time) but is necessary to simulate anything that will experience deformations, as your ship does. This is also extremely sensitive to the simulation step, as the pieces will diverge more and more from a realistic simulation at each step, and the work to make everything converge is more important.

OK now here my speculation of what is happening:

When you warp, the game increase the simulation step. That mean the pieces of you craft diverge more before the joint resolution kicks in. The put your ship back together, it has to go to more extreme solution, bending your craft in the process.

Link to comment
Share on other sites

This is valid strategy used in various physic engine (inf act, most engines use both strategy). The problem is that nothing can be "wobbly" with that approach. Like booster bending inward while thrusting (if they apply more thrust than the main engine), or outward when they run out of fuel. That would still make sens to use this technique between fuel tank, engine and other part of the ship that aren't supposed to bend or wobble.

Link to comment
Share on other sites

Afaik physics warp increases the time step which in most cases is totally unnecessary, most pc's can handle 4x more physics calculations easy on simple crafts in ksp. Imo it should be changed so it didn't increase the time step and give a checkbox option for it to automatically increase time step if it detects its not running in real-time.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...