Skip to content

Commit

Permalink
RoverController: quick fix to use ModuleWheelBase.isGrounded instead …
Browse files Browse the repository at this point in the history
…of Part.GroundContact
  • Loading branch information
Hauke Lampe committed Aug 7, 2020
1 parent 2d0ad46 commit 3a1cd75
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion MechJeb2/MechJebModuleRoverController.cs
Expand Up @@ -107,6 +107,7 @@ public class MechJebModuleRoverController : ComputerModule
public EditableDouble tractionLimit = 75;

public List<Part> wheels = new List<Part>();
public List<ModuleWheelBase> wheelbases = new List<ModuleWheelBase>();
public List<WheelCollider> colliders = new List<WheelCollider>();
public Vector3 norm = Vector3.zero;

Expand Down Expand Up @@ -139,6 +140,13 @@ public void OnVesselModified(Vessel v)
wheels.AddRange(vessel.Parts.FindAll(p => p.HasModule<ModuleWheelBase>() /*&& p.FindModelComponent<WheelCollider>() != null*/ && p.GetModule<ModuleWheelBase>().wheelType != WheelType.LEG));
colliders.Clear();
wheels.ForEach(p => colliders.AddRange(p.FindModelComponents<WheelCollider>()));

wheelbases.Clear();
wheelbases.AddRange(vessel.Parts.Where(
p => p.HasModule<ModuleWheelBase>()
&& p.GetModule<ModuleWheelBase>().wheelType != WheelType.LEG
// && (p.GetModule<ModuleWheels.ModuleWheelSteering>()?.steeringEnabled == true || p.GetModule<ModuleWheels.ModuleWheelMotorSteering>()?.steeringEnabled == true)
).Select(p => p.GetModule<ModuleWheelBase>()));
}
catch (Exception) {}
}
Expand Down Expand Up @@ -188,6 +196,7 @@ public void CalculateTraction()
// }
// }

/*
for (int i = 0; i < wheels.Count; i++)
{
var w = wheels[i];
Expand All @@ -196,6 +205,7 @@ public void CalculateTraction()
traction += 100;
}
}
*/

// for (int i = 0; i < colliders.Count; i++)
// {
Expand All @@ -206,7 +216,16 @@ public void CalculateTraction()
// }
// }

traction /= wheels.Count;
for (int i = 0; i < wheelbases.Count; i++)
{
var w = wheelbases[i];
if (w.isGrounded)
{
traction += 100;
}
}

traction /= wheelbases.Count;
}

public override void OnModuleDisabled()
Expand Down

0 comments on commit 3a1cd75

Please sign in to comment.