Skip to content

Commit

Permalink
Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoak committed Jun 7, 2018
1 parent 3f742ad commit b4336c2
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions Assets/Fishtank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,56 +809,56 @@ void PushRingsDirectly(GameObject go)
}

if (ring.partnerAcceptor != null)
{
//if ( (ring.partnerDonor == null) || ( (ring.partnerDonor != null && (Random.Range(0.0f, 1.0f) < 0.5f))) )
{
var acceptor = ring.partnerAcceptor.transform.Find("tf_stack/donorPos");
var acceptorPos = acceptor.position;
var targetRotation = acceptor.rotation;
var distanceFromAcceptorPos = Vector3.Distance(go.transform.position, acceptorPos);
{
var acceptor = ring.partnerAcceptor.transform.Find("tf_stack/donorPos");
var acceptorPos = acceptor.position;
var targetRotation = acceptor.rotation;
var distanceFromAcceptorPos = Vector3.Distance(go.transform.position, acceptorPos);

{
bestRotationOffsetAngle = GetBestRotationOffsetAngle(acceptor.rotation, go);
//Debug.Log("bestRotationOffsetAngle (acceptor) is " + bestRotationOffsetAngle);
targetRotation = acceptor.rotation * Quaternion.Euler(new Vector3(0, bestRotationOffsetAngle, 0));
}
{
bestRotationOffsetAngle = GetBestRotationOffsetAngle(acceptor.rotation, go);
//Debug.Log("bestRotationOffsetAngle (acceptor) is " + bestRotationOffsetAngle);
targetRotation = acceptor.rotation * Quaternion.Euler(new Vector3(0, bestRotationOffsetAngle, 0));
}

/*
{
// possible optimisation as alternative to code block above
bestRotationOffsetAngle = 360.0f - bestRotationOffsetAngle;
targetRotation = acceptor.rotation * Quaternion.Euler(new Vector3(0, bestRotationOffsetAngle, 0));
Debug.Log("bestRotationOffsetAngle (acceptor) is " + bestRotationOffsetAngle);
}
*/
/*
{
// possible optimisation as alternative to code block above
bestRotationOffsetAngle = 360.0f - bestRotationOffsetAngle;
targetRotation = acceptor.rotation * Quaternion.Euler(new Vector3(0, bestRotationOffsetAngle, 0));
Debug.Log("bestRotationOffsetAngle (acceptor) is " + bestRotationOffsetAngle);
}
*/

if (distanceFromAcceptorPos > minDistApplyRBForcesRing) // use rigidbody forces to push paired game objects together
{
float maxPush = Mathf.Min(distanceFromAcceptorPos * 5.0f, 0.5f); //
go.GetComponent<Rigidbody>().AddForce(Vector3.Normalize((acceptorPos - go.transform.position) + (Random.onUnitSphere * 0.01f)) * Time.deltaTime * Random.Range(0.0f, maxPush), ForceMode.Impulse);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * Random.Range(0.1f, 0.5f) * pairingRotationVelocity);
}
else if (distanceFromAcceptorPos > stackForceDistance)
{
go.transform.position = Vector3.MoveTowards(go.transform.position, acceptorPos, Time.deltaTime * pairingVelocity);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * Random.Range(0.1f, 0.5f) * pairingRotationVelocity);
}
else
{
// update docked flags - used for nanowires
ring.dockedToAcceptor = true;
if (distanceFromAcceptorPos > minDistApplyRBForcesRing) // use rigidbody forces to push paired game objects together
{
float maxPush = Mathf.Min(distanceFromAcceptorPos * 5.0f, 0.5f); //
go.GetComponent<Rigidbody>().AddForce(Vector3.Normalize((acceptorPos - go.transform.position) + (Random.onUnitSphere * 0.01f)) * Time.deltaTime * Random.Range(0.0f, maxPush), ForceMode.Impulse);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * Random.Range(0.1f, 0.5f) * pairingRotationVelocity);
}
else if (distanceFromAcceptorPos > stackForceDistance)
{
go.transform.position = Vector3.MoveTowards(go.transform.position, acceptorPos, Time.deltaTime * pairingVelocity);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * Random.Range(0.1f, 0.5f) * pairingRotationVelocity);
}
else
{
// update docked flags - used for nanowires
ring.dockedToAcceptor = true;

//go.transform.position = Vector3.MoveTowards(go.transform.position, acceptorPos, Time.deltaTime * pairingForcingVelocity);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * pairingForcingRotationVelocity);
// HACK: commented out because there has to be some priority for moving rings based on acceptor / donor pairings
// unfortunately this causes asymmetry in how ring stacks move
//go.transform.position = Vector3.MoveTowards(go.transform.position, acceptorPos, Time.deltaTime * pairingForcingVelocity);
go.transform.rotation = Quaternion.RotateTowards(go.transform.rotation, targetRotation, Time.deltaTime * pairingForcingRotationVelocity);

}
}

if (cheat)
{
go.transform.position = acceptorPos;
go.transform.rotation = targetRotation;
}
if (cheat)
{
go.transform.position = acceptorPos;
go.transform.rotation = targetRotation;
}

}
if (ring.partnerDonor != null)
{
Expand Down Expand Up @@ -981,7 +981,7 @@ private void AddRandomMotion(GameObject go)

if (!ringsUseSpringConstraints)
{
//spring constraint damper interferes with rb movement
//RB spring constraint damper interferes with rb movement
var ring = go.GetComponent<Ring>();
ring.sjDonorToAcceptor.damper = 0;
ring.sjAcceptorToDonor.damper = 0;
Expand Down

0 comments on commit b4336c2

Please sign in to comment.