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.

relative intertial dampener

Discussion in 'Programming Questions and Suggestions' started by thekingmen, Jan 20, 2017.

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

    I have been thinking for a while about an idea. I would like some hint/help on how to do it.
    Inertial dampner is very useful in this game, because without it I can't properly stop. Always moving 0.5km -2 km left, or right or whatever of where I would like to be. Activating the dampener will stop me completly allowing to work/grind. Dampener is working when I am trying to work on a grid that is not moving. However if the grid is moving .. at 20 m/s for example, if I enable the dampner then my character will completly stop and the ship will continue forward, leaving me behind. So in these cases, I need to keep it disabled, and try to stay static relative to the moving grid, which is always impossible - always moving up/down, behind.

    The idea here is to make an ingame script that would controls thruster to dampner relative to another grid in a programmable block.
    If my ship is moving forward at 20m/s, and I move forward at 30m/s, the dampner should slow me down and keep me exactly at 20/ms forward. So from my point of view, it would appear that the ship and I are not moving, and everything else is moving around us.

    I started to check how to do that. First, I need to be able to know the ship speed/velocity. Fortunately, it's already available
    Sandbox.Common/ModAPI/Ingame/IMyShipController.cs contains Vector3D LinearVelocity, which is saved in a Vector3D class. This class contains 3 point (x,y,z) showing how the ship is moving relative to the world.

    Second, I need a way to send that information to a remote ship that wish to follow the first one (for example a builder ship). with the lastest dev, we NOW have a working inter grid communication with the antennas. This will be perfect, simply send the x,y,z coordinates to the remote ship.

    Third, the remote ship need to apply inertial dampener relative to the velocity received. Currently in the game when the dampener are activated, the are basically activated to reach a zero velocity (0 speed in all axes). Here I need to do it to reach a specific velocity (the one from the ship).
    This is the part that is giving me trouble. I tried to think how I would program this, but programming an inertial dampner system seems very though. You need to controll thrust in all direction to slow down gracefully the ship up to a "relative" stop - to the correct speed. Thrusting is easy, but thrusting slowdown from 100%thrust to 80%thrust to 10% and 0% when you are there... is more of a challenge. I don't know how to properly do it.

    With that, one idea would be to "steal" the working code from keep that does the dampening and copy it inside a programmable block.
    I have tried to check the code from space enginners using ILSpy. I think I found some relevant code here, but it's complicated.
    // Sandbox.Game.Entities.MyCubeGrid
    internal void EnableDampingInternal(bool enableDampeners, bool updateProxy)

    // Sandbox.Game.GameSystems.MyEntityThrustComponent
    private void ComputeBaseThrust(ref Vector3 controlThrust, MyEntityThrustComponent.FuelTypeData fuelData, bool applyDampeners)

    From what I understand, they basically calculate a relative target velocity in the zero variable to the max possible thrust of the ship in the opposite direction, then try to apply that velocity to the current velocity with a SlowDownFactor.

    Whoaa..did I wrote a novel ? who's going to read that except me .. ???
    wup, basically, if some people would have a hint on how to program a damper in a PB, or if my understanding of using MyShipController LinearVelocity is correct.
    --- Automerge ---
    Found that script Cruise Control from ZerothAngel can be used to control the speed without ingame dampeners. He use a pid controller to calculate a correction speed for thruster to ajust to a target speed. If set to cruise at zero m/s without any dead zone, it will completly stop in one vector. What's funny is that it will stop faster than the in-game script. Anyway, this provide the dampener that I needed. Now I just need to make it work across the 3 axes, and integrate the solution together. I might have difficulties to ajust the axes based onthe gyros, there already a support for this in the mod but I haven't read it yet.
  2. Xanthyn Trainee Engineer

    I don't know much about writing code but I do think I might have suggestion that could simplify your project: Instead of having two programming blocks communicating with each other, I believe you can use a camera ray cast to detect the speed and direction of another grid. This would allow relative inertial dampening with the use of only one PB, and you could use it on unpowered or enemy grids.
Thread Status:
This last post in this thread was made more than 31 days old.