Jump to content

How to change the lift with deploy and retract?


Recommended Posts

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.

Edited by tarokun3090
Link to comment
Share on other sites

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.

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