Skip to content

Commit 8c4f79a

Browse files
committed
1.0.2-1.0.3
1.0.2: rewrote animation handling to work better with fswheel, fix motor bug 1.0.3 removed debug labels
1 parent ce45b7e commit 8c4f79a

1 file changed

Lines changed: 96 additions & 74 deletions

File tree

BDAnimationModules/BDAdjustableLandingGear.cs

Lines changed: 96 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ public class BDAdjustableLandingGear : PartModule
120120
[KSPField(isPersistant = false)]
121121
public bool mirrorRetractedWheel = false;
122122

123-
AnimationState[] animationStates;
123+
AnimationState anim;
124+
Animation emptyAnimation;
124125

125126

126127
//persistent fields
127128
[KSPField(isPersistant = true)]
128129
public GearStates CurrentState = GearStates.Deploying;
129130

131+
[KSPField(isPersistant = true)]
132+
public GearStates TargetState = GearStates.Deployed;
133+
130134
[KSPField(isPersistant = true, guiActiveEditor = false)]
131135
public bool isMirrored = false;
132136

@@ -248,8 +252,8 @@ public override void OnStart (PartModule.StartState state)
248252
{
249253

250254

251-
animationStates = Utils.SetUpAnimation(animationName, part);
252-
255+
emptyAnimation = part.FindModelAnimators(animationName)[0];
256+
anim = emptyAnimation[animationName];
253257

254258
//set max and min for wheel height
255259
var wheelHeightTweakable = (UI_FloatRange) Fields["wheelHeight"].uiControlEditor;
@@ -298,31 +302,35 @@ public override void OnStart (PartModule.StartState state)
298302
{
299303
animNormTimeP = 0;
300304
}
301-
foreach(AnimationState anim in animationStates)
305+
306+
307+
anim.normalizedTime = animNormTimeP;
308+
//Debug.LogWarning("anim norm time: "+anim.normalizedTime);
309+
310+
float animNormTime = 1-animNormTimeP;
311+
animNormTime = Mathf.Clamp01(animNormTime);
312+
313+
if(animNormTime >= 1)
302314
{
303-
anim.normalizedTime = animNormTimeP;
304-
//Debug.LogWarning("anim norm time: "+anim.normalizedTime);
305-
306-
float animNormTime = 1-anim.normalizedTime;
307-
animNormTime = Mathf.Clamp01(animNormTime);
308-
309-
if(animNormTime >= 1)
310-
{
311-
CurrentState = GearStates.Deployed;
312-
}
313-
else if(animNormTime <= 0)
314-
{
315-
CurrentState = GearStates.Retracted;
316-
}
317-
else if(anim.speed < 0)
318-
{
319-
CurrentState = GearStates.Deploying;
320-
}
321-
else
322-
{
323-
CurrentState = GearStates.Retracting;
324-
}
315+
//emptyAnimation.Stop();
316+
//anim.normalizedTime = 0;
317+
CurrentState = GearStates.Deployed;
318+
}
319+
else if(animNormTime <= 0)
320+
{
321+
//emptyAnimation.Stop();
322+
//anim.normalizedTime = 1;
323+
CurrentState = GearStates.Retracted;
324+
}
325+
else if(anim.speed < 0)
326+
{
327+
CurrentState = GearStates.Deploying;
325328
}
329+
else
330+
{
331+
CurrentState = GearStates.Retracting;
332+
}
333+
326334

327335
//Debug.LogWarning("gear current state: "+CurrentState);
328336

@@ -469,63 +477,73 @@ public void FixedUpdate()
469477

470478
//get animation normalized time and current state
471479
float animNormTime = 0;
472-
foreach(var anim in animationStates)
480+
481+
if(!hasLoaded)
473482
{
474-
if(!hasLoaded)
475-
{
476-
anim.speed = 0;
477-
anim.normalizedTime = animNormTimeP;
478-
hasLoaded = true;
479-
}
480-
else
481-
{
482-
animNormTimeP = anim.normalizedTime;
483-
animSpeedP = anim.speed;
484-
}
485-
486-
deployTime = anim.length;
487-
anim.normalizedTime = Mathf.Clamp01(anim.normalizedTime);
488-
animNormTime = 1-anim.normalizedTime;
489-
490-
foreach(WheelCollider wc in part.FindModelComponents<WheelCollider>())
491-
{
492-
if(animNormTime < 0.2f)
493-
{
494-
wc.radius = 0.0001f;
495-
}
496-
else
497-
{
498-
wc.radius = wheelRadius;
499-
}
500-
}
501-
502-
503-
504-
if(animNormTime >= 1)
505-
{
506-
CurrentState = GearStates.Deployed;
507-
}
508-
else if(animNormTime <= 0)
509-
{
510-
CurrentState = GearStates.Retracted;
511-
}
512-
else if(anim.speed < 0)
483+
//emptyAnimation.Stop();
484+
anim.normalizedTime = animNormTimeP;
485+
hasLoaded = true;
486+
}
487+
else
488+
{
489+
animNormTimeP = anim.normalizedTime;
490+
animSpeedP = anim.speed;
491+
}
492+
493+
deployTime = anim.length;
494+
anim.normalizedTime = Mathf.Clamp01(anim.normalizedTime);
495+
if(emptyAnimation.isPlaying) animNormTime = 1-anim.normalizedTime;
496+
497+
foreach(WheelCollider wc in part.FindModelComponents<WheelCollider>())
498+
{
499+
if(animNormTime < 0.2f && CurrentState != GearStates.Deployed)
513500
{
514-
CurrentState = GearStates.Deploying;
501+
wc.radius = 0.0001f;
515502
}
516503
else
517504
{
518-
CurrentState = GearStates.Retracting;
505+
wc.radius = wheelRadius;
519506
}
520507
}
521508

509+
510+
511+
512+
513+
if(animNormTime == 0 && !emptyAnimation.isPlaying)
514+
{
515+
CurrentState = TargetState;
516+
}
517+
else if(anim.speed < 0)
518+
{
519+
TargetState = GearStates.Deployed;
520+
CurrentState = GearStates.Deploying;
521+
}
522+
else if(anim.speed > 0)
523+
{
524+
TargetState = GearStates.Retracted;
525+
CurrentState = GearStates.Retracting;
526+
}
527+
528+
529+
530+
531+
522532
UpdateDoors();
523533

524534
doorsNormTime = (90/doorSpeed)/deployTime;
525535

526536
deployTime -= 90/doorSpeed;
527537

528538

539+
UpdateGear();
540+
541+
542+
SavePosAndRot();
543+
}
544+
545+
void UpdateGear()
546+
{
529547
//speeds
530548
float deployAngularSpeed;
531549
float tiltAngularSpeed;
@@ -557,6 +575,7 @@ public void FixedUpdate()
557575
float pistonTransAmount = pistonTransSpeed * TimeWarp.fixedDeltaTime;
558576

559577
//moving stuff w/anim
578+
560579
if((CurrentState == GearStates.Deploying && doorsAreOpen) || CurrentState == GearStates.Deployed)
561580
{
562581
deployTransform.localRotation = Quaternion.RotateTowards(deployTransform.localRotation, deployTargetTransform.localRotation, deployAngleAmount);
@@ -580,11 +599,9 @@ public void FixedUpdate()
580599
}
581600
}
582601

583-
584-
SavePosAndRot();
602+
585603
}
586604

587-
588605
void SavePosAndRot()
589606
{
590607
wheelTargetPositionP = deployedWheelTargetTransform.localPosition;
@@ -742,17 +759,22 @@ void UpdateDoors()
742759

743760

744761
}
745-
/*
762+
746763
public void OnGUI()
747764
{
765+
/*
748766
float angleToGround = Vector3.Angle(deployedWheelTargetTransform.forward, Vector3.up);
749767
750768
GUI.Label(new Rect(50,50,200,200),
751-
"local leg angle: "+ tiltTargetTransform.localEulerAngles
769+
"anim is playing: "+ emptyAnimation.isPlaying
770+
+ "\n anim norm time: "+anim.normalizedTime.ToString("0.00")
771+
+ "\n gear state: "+CurrentState
752772
);
753773
774+
*/
775+
754776
}
755-
*/
777+
756778

757779

758780
//Thanks FlowerChild

0 commit comments

Comments
 (0)