Skip to content

Commit

Permalink
Improving terrain extender landing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodrigv committed Jan 8, 2021
1 parent 642ed24 commit 60e7c38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Binary file not shown.
3 changes: 2 additions & 1 deletion PhysicsRangeExtender/PhysicsRangeExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ private void NewVesselIsLoaded(Vessel vessel)
{
Vessel = vessel,
InitialAltitude = vessel.altitude,
InitialPosition = vessel.GetWorldPos3D(),
LandedState = TerrainExtender.LandedVesselsStates.NotFocused
});
}); ;
}


Expand Down
25 changes: 13 additions & 12 deletions PhysicsRangeExtender/TerrainExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ private void ExtendTerrainForLandedVessels()
{
currentVesselData.LandedState = LandedVesselsStates.Focused;
}
currentVessel.SetWorldVelocity(currentVessel.gravityForPos * -8 * Time.fixedDeltaTime);

currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude);
currentVessel.SetWorldVelocity(Vector3.zero);
break;
case LandedVesselsStates.Focusing:

Expand All @@ -118,26 +120,23 @@ private void ExtendTerrainForLandedVessels()
vesselLandedState.LandedState = LandedVesselsStates.Focused;
}
}
currentVessel.SetWorldVelocity(currentVessel.gravityForPos * -8 * Time.fixedDeltaTime);
currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude);
currentVessel.SetWorldVelocity(Vector3.zero);
break;
case LandedVesselsStates.Focused:

if (currentVessel.altitude - currentVesselData.InitialAltitude >= 3d)
{
currentVessel.SetPosition(currentVesselData.InitialPosition + currentVessel.up.normalized * currentVessel.vesselSize.magnitude);
currentVessel.SetWorldVelocity(Vector3.zero);
currentVessel.UpdateLandedSplashed();
currentVesselData.LandedState = LandedVesselsStates.Lifted;
}
else
{
currentVessel.SetWorldVelocity(currentVessel.gravityForPos * -8 * Time.fixedDeltaTime);
currentVessel.UpdateLandedSplashed();
}


break;
case LandedVesselsStates.Lifted:

if (!currentVessel.Landed)
{
currentVessel.SetWorldVelocity(currentVessel.gravityForPos.normalized* 20.0f *Time.fixedDeltaTime);
currentVessel.SetWorldVelocity(currentVessel.gravityForPos.normalized * 20.0f * Time.fixedDeltaTime);

currentVessel.UpdateLandedSplashed();
}
else
Expand Down Expand Up @@ -299,6 +298,8 @@ public class VesselLandedState
public double InitialAltitude { get; set; }

public double TimeOfState { get; set; }

public Vector3d InitialPosition { get; set; }
}
}
}

0 comments on commit 60e7c38

Please sign in to comment.