Include rotation in body alignment calculations

This commit is contained in:
Joshua Thome 2023-03-16 20:14:22 -05:00
parent 7449b7e0f2
commit ee99c5e937
2 changed files with 3 additions and 12 deletions

View File

@ -144,16 +144,6 @@ namespace NewHorizons.Builder.Props
// Items shouldn't use these else they get weird
if (isItem) detail.keepLoaded = true;
if (detail.alignToNormal)
{
Quaternion rot = detail.rotation == null ? Quaternion.identity : Quaternion.Euler(detail.rotation);
// Apply the rotation after aligning it with normal
var up = (prop.transform.position - go.transform.position).normalized;
prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up);
prop.transform.rotation *= rot;
}
prop.transform.localScale = detail.stretch ?? (detail.scale != 0 ? Vector3.one * detail.scale : prefab.transform.localScale);
if (detail.removeChildren != null)

View File

@ -51,8 +51,9 @@ namespace NewHorizons.Builder.Props
}
if (alignToBody)
{
var planetPos = planetGO.transform.InverseTransformPoint(go.transform.position);
go.transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(planetPos.normalized)).normalized;
var up = (go.transform.position - planetGO.transform.position).normalized;
go.transform.rotation = Quaternion.FromToRotation(Vector3.up, up);
go.transform.rotation *= rot;
}
return go;
}