Skip to content

Commit

Permalink
Fixed rotation of spawned vessels
Browse files Browse the repository at this point in the history
  • Loading branch information
IO5 committed Jun 2, 2024
1 parent 4b57f1c commit 4c5438a
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions source/ContractConfigurator/Behaviour/SpawnVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,34 +557,22 @@ protected bool CreateVessels()

// Figure out the surface height and rotation
Quaternion normal = Quaternion.LookRotation(new Vector3((float)norm.x, (float)norm.y, (float)norm.z));
Quaternion rotation = Quaternion.identity;
float heading = vesselData.heading;
if (shipConstruct == null)
{
rotation = rotation * Quaternion.FromToRotation(Vector3.up, Vector3.back);
}
else if (shipConstruct.shipFacility == EditorFacility.SPH)
{
rotation = rotation * Quaternion.FromToRotation(Vector3.forward, -Vector3.forward);
heading += 180.0f;
}
else
var rotation = Quaternion.Euler(vesselData.roll, vesselData.pitch, vesselData.heading);

rotation = rotation * Quaternion.AngleAxis(180, Vector3.up);
if (shipConstruct?.shipFacility != EditorFacility.SPH)
{
rotation = rotation * Quaternion.FromToRotation(Vector3.up, Vector3.forward);
rotation = rotation * Quaternion.FromToRotation(Vector3.forward, Vector3.up);
}

rotation = rotation * Quaternion.AngleAxis(vesselData.pitch, Vector3.right);
rotation = rotation * Quaternion.AngleAxis(vesselData.roll, Vector3.down);
rotation = rotation * Quaternion.AngleAxis(heading, Vector3.forward);

// Set the height and rotation
if (landed || splashed)
{
float hgt = (shipConstruct != null ? shipConstruct.parts[0] : vesselData.craftPart.partPrefab).localRoot.attPos0.y - lowest;
hgt += vesselData.height;
protoVesselNode.SetValue("hgt", hgt.ToString());
}
protoVesselNode.SetValue("rot", KSPUtil.WriteQuaternion(rotation * normal));
protoVesselNode.SetValue("rot", KSPUtil.WriteQuaternion(normal * rotation));

// Set the normal vector relative to the surface
Vector3 nrm = (rotation * Vector3.forward);
Expand Down

0 comments on commit 4c5438a

Please sign in to comment.