Jump to content

tarokun3090

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by tarokun3090

  1. I solved it myself.

    parts.cgf

    MODULE
    {
    	name = ModuleAnimateGeneric
    	animationName = bigsolarpanel
    	actionGUIName = WingToggle
    	startEventGUIName = Deploy
    	endEventGUIName = Retract
    }
    
    MODULE
    {
    	name = ModuleLiftingSurface
    	useInternalDragModel = True
    	deflectionLiftCoeff = 2.0
    	dragAtMaxAoA = 0.5
    	dragAtMinAoA = 0.0
    }
    
    MODULE
    {
    	name = AnimatedWing
    }

     

    source.cs

    using System;
    using UnityEngine;
    
    namespace Utls_AnimatedWing
    {
       public class AnimatedWing : PartModule
        {
            private string animationName = "bigsolarpanel";
            private Animation anim;
            private ModuleLiftingSurface liftingSurface;
            private bool deployOld;
            private bool deployNow;
            private bool init = false;
    
            public override void OnStart(PartModule.StartState state)
            {
                Debug.Log("OnStart() *** AnimatedWing ***");
    
                anim = part.FindModelAnimators(animationName)[0];
                liftingSurface = part.FindModuleImplementing<ModuleLiftingSurface>();
    
                init = true;
                ChangeLift();
            }
    
            private void ChangeLift()
            {
                if (anim == null || liftingSurface == null)
                    return;
    
                float animTm = anim[animationName].normalizedTime;
                deployNow = (animTm < 1.0f) ? false : true;
              
                if (init==true || (deployNow != deployOld)) {
    
                    Debug.Log("ChangeLift() *** AnimatedWing ***");
                    
                    if (deployNow == true) {
                        liftingSurface.deflectionLiftCoeff = 2.0f;
                        liftingSurface.useInternalDragModel = true;
                    }
                    else {
                        liftingSurface.deflectionLiftCoeff = 0.0f;
                        liftingSurface.useInternalDragModel = false;
                    }
                    deployOld = deployNow;
                    if (init == true) init = false;
                }
            }
    
            public void FixedUpdate()
            {
               ChangeLift();
            }
        }
    }

     

    I also have some code that I do not understand, so I need to check it.

  2. I am creating a variable wing that can be deployed and retracted. 
    I want to use ModuleAnimateGeneric and ModuleLiftingSurface of parts.cfg file.

    1. How to change the lift with deploy and retract?
    2. Is there a way to know the current status of deploy and retract?

    I have just started Addon development, and I do not know much about it.
    Thanks for any advice.

×
×
  • Create New...