Jump to content

Get all Active Engines?


Recommended Posts

Hi!

I do it like this:


int NumberOfActiveEngines=0;

for (int i = 0; i <= PART.vessel.parts.Count() - 1; i++)
{
if ((part.vessel.parts.ElementAt(i).GetType().Name == "LiquidFuelEngine")&&(PART.vessel.parts.ElementAt(i).State==PartStates.ACTIVE))
{
uint active=0;
foreach (FXGroup fx in part.vessel.parts.ElementAt(i).fxGroups)//in 0.15, l.engines no longer deactivate when they run out of fuel. This checkes if they emit particles. If so, they are active running engines.
{
foreach (UnityEngine.GameObject gfx in fx.fxEmitters)
{
if(gfx.renderer.particleEmitter.emit) active++;
}
}

if (active>0)//just in case an engine has more than one emitters...
{
NumberOfActiveEngines++;
}
}
}

Yes, it's quite a mess, but at least it works :)

Link to comment
Share on other sites

a similar question, how do I properly set thrust of engines to what I want? I figure this is partially a math phail on me, and partially me not knowing how all the engine variables work... below mainThrust is the 1 - 100 value I have the ability to set via a UI slider:

foreach (LiquidFuelEngine engine in engines)

{

Vector3d v = engine.thrustVector.normalized;

float val = engine.maxThrust*(mainThrust/100);

v.Scale(new Vector3d(val, val, val));

engine.thrustVector = v;

}

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...