Jump to content

Modifying CrashTolerance when I hit the ocean


Recommended Posts

So I want to make it so that when I hit the ocean at a speed less than 1000 m/s (Debug speed) my part survives, but when I hit the land, it doesn't survive if it is greater than 14 m/s here is my code

 using UnityEngine;

namespace OceanExpansion
{
public class OceanCrash : PartModule
{


public void OnStart(Vessel.Situations state)
{
if (state == Vessel.Situations.SPLASHED)
part.crashTolerance = 1000;
else
part.crashTolerance = 6;
}




public void OnLoad(Vessel.Situations state)
{
if (state == Vessel.Situations.SPLASHED)
part.crashTolerance = 1000;
else
part.crashTolerance = 6;
}

public void OnSave(Vessel.Situations state)
{
if (state == Vessel.Situations.SPLASHED)
part.crashTolerance = 1000;
else
part.crashTolerance = 6;
}


}
}

What am I doing wrong?

Link to comment
Share on other sites

I believe the issue is that on the frame you "touchdown", your situation is "in flight", it is not until after you touchdown or splash that your situation goes to splashed.

If so, you are going to need to find a check that will set your crashtolerance to 1000 if over water, to 6 if not.

D.

Link to comment
Share on other sites

If vessel.pqsAltitude is negative, you are over water. You could just have it check if you are over water and under a certain altitude (using vessel.altitude) and then set the crash tolerance. You would have to set it back to 6 otherwise (perhaps using an if/else check).

You also need OnStart to be public override ​void OnStart(Vessel.Situations situation), and OnSave/OnLoad use a ConfigNode for their parameter

Edited by MrHappyFace
Link to comment
Share on other sites

If vessel.pqsAltitude is negative, you are over water. You could just have it check if you are over water and under a certain altitude (using vessel.altitude) and then set the crash tolerance. You would have to set it back to 6 otherwise (perhaps using an if/else check).

You also need OnStart to be public override ​void OnStart(Vessel.Situations situation), and OnSave/OnLoad use a ConfigNode for their parameter

Actually it's OnStart(PartModule.StartState state)

Link to comment
Share on other sites

Thanks everybody!

here's what I have now. When I used public override void, it said "no suitable method to override"

 using UnityEngine;

namespace OceanExpansion
{
public class OceanCrash : PartModule
{

bool aboveWater = false;


public void OnStart()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;

else
part.crashTolerance = 14;


do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}






public void OnLoad()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
else
part.crashTolerance = 14;


do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}

public void OnSave()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
else
part.crashTolerance = 14;

do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}


public void overWater()
{
do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);

}

}


}

Still goes boom when it hits the water.

Edited by kineticPull
Link to comment
Share on other sites


if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;

else
part.crashTolerance = 14;

Can you add some logging to this? When I did my lander height mod I had to add error trapping because over deep water it seemed that the PQS layer did not exist.

I'm wondering if that IF statement is returning false because the PQS layer does not exist where you are testing and so returns FALSE as a null value can not be compared to.

D.

edit: Umm, actually, where is your Update() method? Right now, you check for over water and set the partTolerance as you intend once when you load the flight scene, once when the game saves and once when the game loads.

There is nothing in there to check for over water at any other time during the flight. I think all you need to do is change the public void overWater() to public void Update() and you will be fine.

Edited by Diazo
Link to comment
Share on other sites

Thanks. I just got started with this plugin developing yesterday, so I don't really know what I'm doing.

Also, I tried using vessel.VerticalSpeed to have the part only survive high velocity landings if the they were horizontal. Here's what I have.


if (vessel.verticalSpeed <= VSplashTolerance)
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = HSplashTolerance;

else
part.crashTolerance = VSplashTolerance;
}

The part survived all water landings no matter how fast.

I might have a page in Add on Development tomorrow...

Edited by kineticPull
Link to comment
Share on other sites

Thanks everybody!

here's what I have now. When I used public override void, it said "no suitable method to override"

 using UnityEngine;

namespace OceanExpansion
{
public class OceanCrash : PartModule
{

bool aboveWater = false;


public void OnStart()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;

else
part.crashTolerance = 14;


do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}






public void OnLoad()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
else
part.crashTolerance = 14;


do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}

public void OnSave()
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
else
part.crashTolerance = 14;

do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);
}


public void overWater()
{
do
{
if (vessel.PQSAltitude() <= 0)
part.crashTolerance = 1000;
if (vessel.PQSAltitude() <= 0)
aboveWater = true;
} while (aboveWater == false);

do
{
if (vessel.PQSAltitude() >= 0)
part.crashTolerance = 14;
if (vessel.PQSAltitude() >= 0)
aboveWater = false;
} while (aboveWater == true);

}

}


}

Still goes boom when it hits the water.

you NEED it to have like this:


public override void OnStart(PartModule.StartState state)
{
[COLOR=#a9a9a9]your code[/COLOR]
}

Also, OnStart is only called once, at the beginning of the flight scene, so you should probably change it to:


public override void OnUpdate()
{
[COLOR=#a9a9a9]your code[/COLOR]
}

Edit: Ninja'd

Link to comment
Share on other sites


using UnityEngine;

namespace OceanExpansion
{
public class OceanCrash : PartModule
{

[KSPField]
public float HSplashTolerance;

[KSPField]
public float VSplashTolerance;

[KSPField]
public double VSplash;

public double vertical;


public void OnStart()
{

if (vertical <= VSplash)
{
if (vessel.PQSAltitude() <= 0)
{
part.crashTolerance = HSplashTolerance;
}
else
{
part.crashTolerance = VSplashTolerance;
}
}
else
{
part.crashTolerance = VSplashTolerance;
}
vertical = vessel.verticalSpeed;

}






public void OnLoad()
{
vertical = vessel.verticalSpeed;
if (vertical <= VSplash)
{
if (vessel.PQSAltitude() <= 0)
{
part.crashTolerance = HSplashTolerance;
}
else
{
part.crashTolerance = VSplashTolerance;
}
}
else
{
if (vertical > VSplash)
{
part.crashTolerance = VSplashTolerance;
}
}


}

public void OnSave()
{
vertical = vessel.verticalSpeed;
if (vertical <= VSplash)
{
if (vessel.PQSAltitude() <= 0)
{
part.crashTolerance = HSplashTolerance;
}
else
{
part.crashTolerance = VSplashTolerance;
}
}
else
{
if (vertical > VSplash)
{
part.crashTolerance = VSplashTolerance;
}
}


}


public void Update()
{
if (vertical <= VSplash)
{
if (vessel.PQSAltitude() <= 0)
{
part.crashTolerance = HSplashTolerance;
}
else
{
part.crashTolerance = VSplashTolerance;
}
}
else
{
if (vertical > VSplash)
{
part.crashTolerance = VSplashTolerance;
}
}

vertical = vessel.verticalSpeed;

}

}


}

Here's my current code. It runs fine in ksp, and the part (KORD drop pod) does what it is supposed to. It has a 1000 crash tolerance over water, and a 14 over land. my current problem is making a vertical speed of >14 m/s over water destroy the pod, where a >14 m/s horizontal speed over water will not.

Edited by kineticPull
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...