Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rotation of spawned vessels #44

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.VAB)
{
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
Loading