Skip to content

Commit

Permalink
set CameraManager.activeInternalPart so that RPM knows what part the …
Browse files Browse the repository at this point in the history
…kerbal is in
  • Loading branch information
JonnyOThan committed Feb 2, 2023
1 parent 2b5ca0f commit cf8327a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
69 changes: 33 additions & 36 deletions FreeIva/FreeIva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,54 +315,51 @@ public void UpdateCurrentPart()

if (possibleParts.Count == 1)
{
//Debug.Log("# Only one part found: " + possibleParts[0]);
CurrentPart = possibleParts[0];
if (CurrentPart != lastPart)
OnIvaPartChanged.Fire(CurrentPart);
/*else
Debug.Log("# Same part as before: " + CurrentPart + " at " + CurrentPart.transform.position);*/
return;
}

float minDistance = float.MaxValue;
Part closestPart = null;
//Debug.Log("# Checking " + possibleParts.Count + " possibilities.");
foreach (Part pp in possibleParts)
else if (possibleParts.Count > 1)
{
Profiler.BeginSample("Testing possible part");
// Raycast from the camera to the centre of the collider.
// TODO: Figure out how to deal with multi-collider parts.
Vector3 c = pp.collider.bounds.center;
Vector3 direction = c - camPos;
Ray ray = new Ray(camPos, direction);
RaycastHit hitInfo;
if (!pp.collider.Raycast(ray, out hitInfo, direction.magnitude))
float minDistance = float.MaxValue;
Part closestPart = null;
//Debug.Log("# Checking " + possibleParts.Count + " possibilities.");
foreach (Part pp in possibleParts)
{
//Debug.Log("# Raycast missed part from inside: " + pp);
// Ray didn't hit the collider => we are inside the collider.
float dist = Vector3.Distance(pp.collider.bounds.center, camPos);
if (dist < minDistance)
Profiler.BeginSample("Testing possible part");
// Raycast from the camera to the centre of the collider.
// TODO: Figure out how to deal with multi-collider parts.
Vector3 c = pp.collider.bounds.center;
Vector3 direction = c - camPos;
Ray ray = new Ray(camPos, direction);
RaycastHit hitInfo;
if (!pp.collider.Raycast(ray, out hitInfo, direction.magnitude))
{
closestPart = pp;
minDistance = dist;
//Debug.Log("# Raycast missed part from inside: " + pp);
// Ray didn't hit the collider => we are inside the collider.
float dist = Vector3.Distance(pp.collider.bounds.center, camPos);
if (dist < minDistance)
{
closestPart = pp;
minDistance = dist;
}
/*else
Debug.Log("# Part was further away: " + minDistance + " vs part's " + dist);*/
}
/*else
Debug.Log("# Part was further away: " + minDistance + " vs part's " + dist);*/
Debug.Log("# Raycast hit part from outside: " + pp);*/
Profiler.EndSample();
}
if (closestPart != null)
{
CurrentPart = closestPart;
}
/*else
Debug.Log("# Raycast hit part from outside: " + pp);*/
Profiler.EndSample();
}
if (closestPart != null)

if (CurrentPart != lastPart)
{
Profiler.BeginSample("OnIvaPartChanged");
//Debug.Log("# New closest part found: " + closestPart);
CurrentPart = closestPart;
if (CurrentPart != lastPart)
OnIvaPartChanged.Fire(CurrentPart);
CameraManager.Instance.activeInternalPart = CurrentPart;
OnIvaPartChanged.Fire(CurrentPart);
Profiler.EndSample();
/*else
Debug.Log("# Same part as before: " + CurrentPart + " at " + CurrentPart.transform.position);*/
}
/*else
Debug.Log("# No closest part found.");*/
Expand Down
1 change: 1 addition & 0 deletions FreeIva/InternalModules/Hatches/Hatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ static Transform FindAirlock(Part part, string airlockName)
return part.airlock;
}

// NOTE: this code has been copied to RPM - should also be updated there if we make any changes
KerbalEVA SpawnEVA(ProtoCrewMember pCrew, Part airlockPart, Transform fromAirlock)
{
var flightEVA = FlightEVA.fetch;
Expand Down

0 comments on commit cf8327a

Please sign in to comment.