Open Ippo343 opened 10 years ago
This could be done pretty simply by tracking the force on the party's rigid body. Since
F = ma
I think it's safe to assume that the crash tolerance of a part is really just
Max_force/wet_mass
And from there we can find the max force on the part. I think the way to go would be to find that, and then find force on the rigid body and find the difference between that (or 0, whichever's smaller, because that way you don't have adverse performance in 0 g) and use that (* a constant) to get the aging factor.
That said, I have no idea how to source an equation for that.
Of course, this might be wildly inaccurate, but I think it's a sound approach in theory.
Unfortunately no, crash tolerance in KSP is a speed, not an acceleration... You need to find a way to get the impact speed to compare that to the crash tolerance, I think.
We can add a OnCollisionStay
hook to the FailureModule
class and then find collision.relativeVelocity
to compute the effect on age. The reason you would use OnCollisionStay instead of OnCollisionEnter is so that if you are still colliding/scraping against something the multiplier stays high.
Perhaps we then store the relative velocity...
void OnCollisionStay(Collision collision) {
this.lastCollisionVelocity = collision.relativeVelocity;
}
and return it in a CrashMultiplier
function...
private float CrashMultiplier(){
float value = 1 + ( (Collision.relativeVelocity / crashTolerance) * CRASH_CONSTANT);
this.lastCollisionVelocity = 0;
return value;
}
I think a good value for CRASH_CONSTANT would be ~0.8
but i'm not really sure.
Then we replace FailureModule.cs#L427 with
this.Age += (dt * this.TemperatureMultiplier() * this.CrashMultiplier());
What do you think?
Well, a collision is a discrete event, not something that happens continuously (hopefully :P ), so there's no need to handle it in Update(): we can simply just bump the age once in onCollisionStay
void OnCollisionStay(Collision collision) {
this.Age += some_function_of(collision.relativeVelocity);
}
Also, judging only from the names, are you sure we don't want this to be in onCollisionEnter?
Sorry for being so absent, I'm working ~60 hours per week :/
Good point. The reason I was thinking it would go in onCollisonStay
instead of onCollisionEnter
is so that you still get age debuffs for scraping along the ground. This of course would need some balance testing...
On the note of what would be in some_function_of
I think we could use
this.Age += this.LifetimeSecs * ( (collision.relativeVelocity / this.part.maxImpactSpeed) / IMPACT_CONSTANT )
I think a good value for IMPACT_CONSTANT
would be ~2? That way a collision at 1/10th of the max speed of the part would add 5% to its age.
P.S. Yikes! Hope the job is fun :open_mouth: , and no problem! I'm pretty busy with FRC this time of year :fried_shrimp: too
A collision should cause the part to age proportionally to the violence of the impact.
Specifically, I mean to increase the part's age by multiplying it by the factor:
where v is the impact velocity, V the crash tolerance, and c a sensitivity factor.