// Update is called once per frame void Update() { ConstraintSource Current = constraint.GetSource(0); ConstraintSource Option = constraint.GetSource(1); //float d = Vector3.Distance(Current.sourceTransform.position, Option.sourceTransform.position); //float offset = 3f; //d = Mathf.Clamp(d, 0f, offset); //d /= offset; Current.weight = 1; Option.weight = 0; Current.weight -= ballWeight; Option.weight += ballWeight; //Current.weight = Mathf.Clamp(Current.weight, 0f, 1f); //Option.weight = Mathf.Clamp(Option.weight, 0f, 1f); constraint.SetSource(0, Current); constraint.SetSource(1, Option); }
float CalcSize() { float maxSize = 0f; Vector3 maxVector3 = Vector3.zero; for (int i = 0; i < PositionConstraint.sourceCount; i++) { for (int j = 0; j < PositionConstraint.sourceCount; j++) { if (i != j) { _Calc = (PositionConstraint.GetSource(i).sourceTransform.position - PositionConstraint.GetSource(j).sourceTransform.position); float _calc = _Calc.magnitude; if (_calc > maxSize) { maxSize = _calc; maxVector3 = _Calc; } } } } if (Mathf.Abs(maxVector3.z) > 3f) { maxSize *= 1.25f; } return(maxSize * factor); }
private void Awake() { if (!reference && Camera.main) { reference = Camera.main.transform; } if (!positionConstraint) { positionConstraint = reference.GetComponent <PositionConstraint>(); } source = positionConstraint.GetSource(index); }