Jump to content

Particle Effect lose its world velocity at specific altitude.


Recommended Posts

Hello, I'm developer of Dump & Burn. I'm tring to upgrade my mod to 1.2. But having some trouble.

When flown about 150~200m from the surface, The particle effect moves together with the ship. not like smoke trail.

However, if flown under the specific alt, it works right just like photo #2.

I'm attaching the code and the screenshot of unity. Need your help.

4n6158V.jpg

 

Wgyo4DB.jpg

FyFYRQ5.png

namespace sakyDST
{
    public class ModuleFueldump : PartModule
    {
        [KSPField(guiActive = true, guiActiveEditor = false, guiName = "Status", isPersistant = true)]
        string status;
        [KSPField(guiActive = false, guiActiveEditor = false, guiFormat = "F1", guiName = "Fuel Amount", guiUnits = " ℓ", isPersistant = true)]
        double fuel;
        [KSPField(guiActive = true, guiActiveEditor = true, guiFormat = "F1", guiName = "Nozzle Size", guiUnits = " cm²", isPersistant = true), UI_FloatRange(affectSymCounterparts = UI_Scene.Editor, controlEnabled = true, maxValue = 10f, minValue = 0.1f, scene = UI_Scene.Editor)]
        float nozzleSize;
        [KSPField(guiActive = false, guiActiveEditor = false, guiFormat = "F0", guiName = "Tanks found", isPersistant = true)]
        int tanks;

        [KSPAction("Toggle Nozzle")]
        public void ActionToggle(KSPActionParam ap)
        {
            EventToggle();
        }
        [KSPAction("Open Nozzle")]
        public void ActionOpen(KSPActionParam ap)
        {
            part.enabled = true;
        }
        [KSPAction("Close Nozzle")]
        public void ActionClose(KSPActionParam ap)
        {
            part.enabled = false;
        }
        [KSPAction("Heat Up Nozzle")]
        public void ActionHeat(KSPActionParam ap)
        {
            part.temperature = 500;
        }
        [KSPEvent(active = true, externalToEVAOnly = false, guiActive = true, guiActiveEditor = false, guiActiveUncommand = false, guiActiveUnfocused = false, name = "toggleNozzle", guiName = "Toggle Nozzle")]
        public void EventToggle()
        {
            part.enabled = !part.enabled;
        }

        KSPParticleEmitter smoke;
        KSPParticleEmitter flame;
        public void initializeFX()
        {
            smoke.
            foreach (KSPParticleEmitter fx in part.FindModelComponents<KSPParticleEmitter>())
            {
                if (fx.name == "emit") smoke = fx;
                if (fx.name == "burn") flame = fx;
            }
            smoke.emit = false;
            flame.emit = false;
        }

        public void CheckFx()
        {            
            int ignitionTemp = 400;
            if (part.enabled)
            {
                if (part.temperature < ignitionTemp)
                {
                    smoke.emit = true;
                    flame.emit = false;
                }
                else
                {
                    smoke.emit = false;
                    flame.emit = true;
                }
            }
            else
            {
                smoke.emit = false;
                flame.emit = false;
            }
        }

        public void Update()
        {
            print("Update");
            CheckFx();
            statusDisplay();
        }

        public override void OnUpdate()
        {
            print("onUpdate");
            EstimateFuel();
            consumeFuel();

            base.OnUpdate();
        }

        public override void OnLoad(ConfigNode node)
        {
            print("onLoad");
            nozzleSize = float.Parse(node.GetValue("nozzleSize"));
            part.enabled = false;

            base.OnLoad(node);
        }
        
        public override void OnInitialize()
        {
            print("onInitialize");
            initializeFX();
            part.enabled = false;

            base.OnInitialize();
        }

        public void statusDisplay()
        {
            status = part.enabled ? "Opened" : "Closed";
        }

        public void consumeFuel()
        {
            if (part.temperature >= 400)
            {
                status += " / T:" + part.temperature + "K";
            }
            foreach (Part p in vessel.parts)
            {
                foreach (PartResource r in p.Resources)
                {
                    if (r.resourceName == "LiquidFuel" && r.amount > 0)
                    {
                        r.amount -= nozzleSize / tanks * UnityEngine.Time.deltaTime;
                        if (r.amount < 0) r.amount = 0;
                    }
                }
            }
        }

        public void EstimateFuel()
        {
            double tmpfuel = 0;
            int tmptanks = 0;

            foreach (Part p in vessel.parts)
            {
                foreach (PartResource r in p.Resources)
                {
                    if (r.resourceName == "LiquidFuel")
                    {
                        tmpfuel += r.amount;
                        tmptanks++;
                    }
                }
            }
            fuel = tmpfuel;
            tanks = tmptanks;
            if (fuel <= 0)
            {
                status = "TANK EMPTY";
                part.enabled = false;
            }
        }

    }
}

There's no altitude related code nor world, local settings.

 

The second problem is,

The part has autostruct/root part? option until it once enabled. After enabled, those menues disappear. Sometimes, the part disappears without any explosion, debrief(F3). Sometimes, it flys chasing me or just fly to other direction. And its not detached, so I can turn on, turn off the nozzle while its flying. I don't know whats going on. Help me. Please...

Edited by rkfnql322
Link to comment
Share on other sites

2 hours ago, rkfnql322 said:

When flown about 150~200m from the surface, The particle effect moves together with the ship. not like smoke trail.

You need to register your emitter with EffectBehaviour.AddParticleEmitter( emitter)  (and unregister when the part is destroyed so RemoveParticleEmitter in the module OnDestroy) to have the particle offset handled when FloatingOrigin starts.

Link to comment
Share on other sites

12 minutes ago, sarbian said:

You need to register your emitter with EffectBehaviour.AddParticleEmitter( emitter)  (and unregister when the part is destroyed so RemoveParticleEmitter in the module OnDestroy) to have the particle offset handled when FloatingOrigin starts.

holy magic. You just ended my problem in 1 sentence. Now we can update the mod. amazing. thanks. thanks^10000.

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