Jump to content

martincmartin

Members
  • Posts

    75
  • Joined

  • Last visited

Reputation

7 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I have a MonoBehavior subclass. I take the difference in ActiveVessel's angularMomentum between successive calls to FixedUpdate(), to see how much torque was applied over the last timestep. This all works well, except when I revert flight, switch vessels, etc. How can I tell whether I'm in the first call to FixedUpdate() after such a change?
  2. I just found one possible reason: if you have a direction (e.g. the direction towards prograde in your vessel's coordinates), the recommended way to get a rotation object from that is to use Quaternion.LookRotation(). But that assumes the "forward" direction is along z, and KSP assumes its along y. That is, they're separated by a rotation of 90 degrees about the X axis, which swaps Y & Z (as well as changing the sign of one, but that doesn't matter for LookRotation().)
  3. Why are Orbit's pos and vel in "AliceWorld" (y & z flipped)? Other than confusing developers, what purpose does it serve? Easier to translate into UI or something?
  4. I'm just quoting the "Modders Notes for KSP 1.2" that you linked to (thanks again for linking to that!). It contains the line: What does it mean by "not valid"? Is it just the value from the last physics update, or garbage numbers? I've been assuming its the value from the last physics update. Of course, the first frame after you switch to it, it could be a very old & essentially garbage number. But after that, hopefully it will be ok.
  5. I am! And I want to use srf_velocity in my physics calculations, e.g. to know which direction is prograde (relative to surface, not orbit). But it seems srf_velocity is only valid in Update(), not FixedUpdate().
  6. Thanks! I also found this tidbit: Is there any way to get them between physics updates? That is, if FixedUpdate() is called 3 times between calls to Update(), is there any way to get srf_velocity and/or obt_velocity after each one? I guess I'll need to compute them myself...
  7. I did a little test: launch a rocket straight up, and a few seconds later (before drag can become significant), cut thrust (by pressing X). If I compute acceleration by subtracting consecutive Vessel.velocityD and dividing by time, I get what I would expect: between two frames, the acceleration instantly changes direction, and the new magnitude is 9.799. However, the "acceleration" field barely changes: See my log messages below: accel: (-3.475, 0.034, 2.243)(4.136), computed: (-3.487, 0.037, 2.255) (4.153), vel: (-29.271, 0.098, 19.660) accel: (-3.477, 0.034, 2.244)(4.138), computed: (-3.489, 0.037, 2.255) (4.154), vel: (-29.340, 0.099, 19.705) accel: (-2.900, 0.034, 1.854)(3.442), computed: (8.082, 0.016, -5.541) (9.799), vel: (-29.179, 0.099, 19.594) accel: (-2.323, 0.033, 1.465)(2.747), computed: (8.082, 0.016, -5.541) (9.799), vel: (-29.017, 0.100, 19.483) accel: (-1.746, 0.032, 1.075)(2.051), computed: (8.082, 0.016, -5.540) (9.798), vel: (-28.855, 0.100, 19.372) (The single number in parentheses is the magnitude). This is while Krakensbane.GetFrameVelocity() is still zero, so there's no floating origin problem. It's only about 4 seconds after lift off. Is the acceleration field some sort of time-averaged value? Once I shut off the engines, nothing on the vessel is actually accelerating at that rate. What is going on? I'll be happy to update the API docs with any answer.
  8. Can we unpin this thread? There are three pinned threads that claim they're the documentation for the API. From what I can tell, this is completely subsumed by the "New KSP API Documentation" thread?
  9. Thanks a lot Crzyrndm, that's very helpful. I put print("fixedDT: " + TimeWarp.fixedDeltaTime + ", deltaT: " + TimeWarp.deltaTime); in FixedUpdate(), turned warp up, and observed that deltaTime was always exactly equal to fixedDeltaTime from the previous print line. In FixedUpdate() I have: Vector3d deltaVelocity = FlightGlobals.ActiveVessel.velocityD - prevVelocity; print("accel: "+vessel.acceleration+", from fixedDT: "+(deltaVelocity / TimeWarp.fixedDeltaTime)+", from deltaT: "+(deltaVelocity / TimeWarp.deltaTime)); prevVelocity = FlightGlobals.ActiveVessel.velocityD; Then I launch a vessel and have it go straight up (roughly constant acceleration), and warp time, and I get: fixedDT: 0.02126373, deltaT: 0.02084686 accel: [-3.676, 0.070, 2.229], from fixedDT: [-3.615, 0.073, 2.193], from deltaT: [-3.687, 0.074, 2.237] ---------- fixedDT: 0.04007141, deltaT: 0.02126373 accel: [-3.682, 0.071, 2.231], from fixedDT: [-1.958, 0.040, 1.187], from deltaT: [-3.690, 0.075, 2.236] ------------- fixedDT: 0.0408728, deltaT: 0.04007141 accel: [-3.848, 0.075, 2.329], from fixedDT: [-3.621, 0.074, 2.193], from deltaT: [-3.693, 0.075, 2.237] So, if we compute using fixedDeltaTime, our computed accel is 1/2 size for a frame during the transition, but if we used deltaT, we're within a few percent, but not exact. I'll look into the two frame back thing when I get a sec, thanks for the tip. And thanks for the tip about the Krakensbane class, I had hear the name but didn't realize it was the name of a class! I should have guessed.
  10. It turns out, TimeWarp.fixedDeltaTime is the time used in the next physics calculation. For my purposes, where I save the previous angularVelocity and subtract it from the current one, I want the value from the prev frame, which is TimeWarp.deltaTime. Thanks for the tip about floating origin, I didn't know about that so I read up about it. Where can I find the velocity of the floating origin? I tried computing vessel.acceleration from the various velocities in vessel (velocityD, rb_velocity, srf_velocity, obt_velocity) but couldn't get the correct answer. Perhaps correcting for the floating point origin velocity will help?
  11. Thanks for the tip! I thought physics was run once per Update(), but looking more closely I see its run once per FixedUpdate(): https://docs.unity3d.com/Manual/ExecutionOrder.html I'm actually looking for angular acceleration, I'm just differentiating angularVelocityD, I'm working on a kind of improved SAS. I couldn't find that in Vessel, is it there and I'm not seeing it?
  12. I'm computing some accelerations by recording velocities during every Update() call, recording elapsed time, and computing (currentV - previousV) / (previousT - currentT). I'm currently using mission time as my time, but (a) it doesn't advance while on the pad (not really a problem, but) (b) when the game is paused, it increases for the first two frames after the game is paused, but the physics isn't running, so all my accelerations are suddenly zero. What's a good value to use for physics time? Ideally: Doesn't advance when the game is paused Take into account warp, e.g. advances 3x as fast when warp is 3x (assuming Update() is still only called once, not 3 times?) Or is there a way to get "elapsed physics time since last call to Update()" directly?
  13. FlightInputHandler.state.yaw shows the user's input, but not what comes from SAS. Where can I find the value used for physics calculations, whether it comes from the user, SAS, a mod, etc?
  14. I just updated to 1.2.1, and now there's no KSPUtil.dll anywhere in my KSP directory. Is this only gone on Mac, or is it also gone on Windows? Can I remove it from my project?
  15. Thanks, that's a helpful starting point. Maybe your response should be made into a wiki page? Would be great if people could find it easily after this thread is buried. And it helps to remember that at low speed KSP is only simulating a small bubble, that explains a lot about the reference frames. The vessel really is at the center of the Universe.
×
×
  • Create New...