Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Questions about thrusters

Discussion in 'Programming Questions and Suggestions' started by MajorTwitch, Mar 25, 2016.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. MajorTwitch Trainee Engineer

    Messages:
    4
    I am slowly attempting to learn how write scripts for this game...

    The question can or how do you check if a thruster active/being used or can you check how much power it is using?

    Not related to thrusters but is there an easy way to detect a "forward" velocity base off your controller block facing?
     
  2. Wicorel Senior Engineer

    Messages:
    1,262
    No. There's no way to tell if the thruster is being used for movement (except if overridden).

    Not easily. You can keep track of positions between script runs and calculate velocity. However, this gets more complex than it should be because of Simspeed.

    I do this in my control script if you want an example (warning: the code is a bit complex/complicated).
     
  3. MajorTwitch Trainee Engineer

    Messages:
    4
    Well have read there is way so get timer blocks to trigger on frame which allows you to far more consistent then using normal time due the simspeed...

    I pretty much new to programming in general. Is your control script commented/annotated or would be weeks of trying to learn what it does? My real goal was to try to have gravity engines automatically assist the main thrusters (at least for forwards and backwards). Gravity gyros would be awesome too, but more I learn about ship physics and how grav engines work the less likely that seems. I want to trying programing it myself, but it is starting to prove far more of a challenge then I imaged.

    I guess this may have already be done by someone, but I couldn't find. The bottom line is could your control script be adapted for such a purpose?
     
  4. Wicorel Senior Engineer

    Messages:
    1,262
    I've posted my code multiple times, it seems. Here is that latest post.

    I've updated this code slightly in my Craft Control Script to automatically calculate fAssumeElapsed as it changes greatly depending on the world.

    Here is an example of the script in action:
     
  5. Lynnux Junior Engineer

    Messages:
    881
    A bit late, sorry, but an easy way to get the forward speed (and more):
    Kinematics - Kinematic measurement helper
    by player2k

    At the beginning of the script:
    Code:
    const double secondsElapsedInv = 60.0;
    Kinematics kim = null;
    
    Somewhere in the Main() method:
    Code:
    float fSpd = 0.0f;
    
      if(kim==null) {
        kim = new Kinematics(Me.CubeGrid,null);
      } else {
        kim.Update(secondsElapsedInv);
        fSpd = (float)(-kim.VelocityLinearCurrent.Z);
        var gforce = fSpd * kim.VelocityAngularCurrent.X / 9.81;
        kimString = "G-Force:                "+gforce.ToString("F1")+" g\n"
        +"Forward:                "+fSpd.ToString("F2")+" m/s\n";
      }
    
    In this case the kinematic data of the CubeGrid of the programmable block is used (=the ship). secondsElpasedInv will simply be 60.0 if you execute the script every tick (60 times a second).
    I recommend the use of the fixed value and not ElapsedTime of the programmable block because ElapsedTime usually causes glitches.

    And hey, see, you'll get the relatively accurate g-force of a turn as a bonus but it's only useful for aeroplanes ;)

    Prerequisite for this to work is that the orientation of your cockpit/flight seat/remote control is "forward, up" on the grid. You'll see that the forward speed is 0 or negative if the orientation is different from the orientation of the grid. In this case you have likely built your ship sideways. You can reorient the blocks on your grid via midspace's excellent Custom Importer/Editor tool - SEToolbox.
    Or you find out the orientation of your ShipController-block and use the correct components of the vectors.

    In my example the speedvector [m/s] is:
    forward: -VelocityLinearCurrent.Z
    left: VelocityLinearCurrent.X
    up: VelocityLinearCurrent.Y

    Rotation speed [rad/s] around the "left-right" axis (=pitch):
    VelocityAngularCurrent.X
    --- Automerge ---
    Or you use the new speed info provided by the ShipController now, of course. Should be easier since the directions will always be as I wrote above.
     
    Last edited: May 20, 2016
  6. mze9412 Junior Engineer

    Messages:
    791
    Which glitches does ElapsedTime have and is @Malware aware of them? He added it in the PB and might be able to fix glitches o_O
     
  7. Malware Master Engineer

    Messages:
    9,861
    @Lynnux, @mze9412 I fixed ElapsedTime (I hope) when I obsoleted it and replaced it with Runtime.TimeSinceLastRun.
     
  8. mze9412 Junior Engineer

    Messages:
    791
    I confused ElapsedTime and TimeSinceLast Run :) I only use the last one and I remembered something about you fixing it, yeah :)
     
Thread Status:
This last post in this thread was made more than 31 days old.