コード例 #1
0
	void TransformChanger ()
	{
		InvertedEffector = theEffector.Inverted;
		Refinecurve = theEffector.FallOffCurve;
		EffectorDistance = theEffector.EffectorDistance;
		EffectorRecoverySpeed = theEffector.EffectorRecoverySpeed;

		for (int i = 0; i < originalObjects.Length; i++) {
			float x, y, z;
			Vector3 posstatic = new Vector3 (OriginalX [i], OriginalY [i], OriginalZ [i]);
			float dist = Vector3.Distance (posstatic, Effector.transform.position);
			normalizedCurve = (dist - rangeSmallest) / (EffectorDistance - rangeSmallest);
			curveValue = Refinecurve.Evaluate (normalizedCurve);
			x = OriginalX [i] + TranslateX*curveValue;
			y = OriginalY [i] + TranslateY*curveValue;
			z = OriginalZ [i] + TranslateZ*curveValue;

				float new_x = x;
				float new_y = y;
				float new_z = z;

				newObjectPos = new Vector3 (new_x, new_y, new_z);
				displacedObjects [i] = newObjectPos;
			}
	
		if (!InvertedEffector) {
			for (int x = 0; x < originalObjects.Length; x++) {

				OriginalsPos.Set (OriginalX [x], OriginalY [x], OriginalZ [x]);
				if (Vector3.Distance (OriginalsPos, Effector.transform.position) <= EffectorDistance) {

					movedObjects [x].position = Vector3.Lerp (movedObjects [x].position, displacedObjects [x], EffectorRecoverySpeed * Time.deltaTime);
				} else {
					originalsLerper.Set (OriginalX [x], OriginalY [x], OriginalZ [x]);
					movedObjects [x].position = Vector3.Lerp (movedObjects [x].transform.position, originalsLerper, EffectorRecoverySpeed * Time.deltaTime); 
				}
			}
		}
		else {
			for (int x = 0; x < originalObjects.Length; x++) {

				OriginalsPos.Set (OriginalX [x], OriginalY [x], OriginalZ [x]);
				if (Vector3.Distance (OriginalsPos, Effector.transform.position) > EffectorDistance) {
					movedObjects [x].position = Vector3.Lerp (movedObjects [x].position, displacedObjects [x], EffectorRecoverySpeed * Time.deltaTime);
				} else {
					originalsLerper.Set (OriginalX [x], OriginalY [x], OriginalZ [x]);
					movedObjects [x].position = Vector3.Lerp (movedObjects [x].transform.position, originalsLerper, EffectorRecoverySpeed * Time.deltaTime); 
				}
			}
		}
	}
コード例 #2
0
    void TransformChanger()
    {
        InvertedEffector      = theEffector.Inverted;
        Refinecurve           = theEffector.FallOffCurve;
        EffectorDistance      = theEffector.EffectorDistance;
        EffectorRecoverySpeed = theEffector.EffectorRecoverySpeed;

        for (int i = 0; i < originalObjects.Length; i++)
        {
            float   x, y, z;
            Vector3 posstatic = new Vector3(OriginalX [i], OriginalY [i], OriginalZ [i]);
            float   dist      = Vector3.Distance(posstatic, Effector.transform.position);
            normalizedCurve = (dist - rangeSmallest) / (EffectorDistance - rangeSmallest);
            curveValue      = Refinecurve.Evaluate(normalizedCurve);

            x = oriRotX [i] + RotateX * curveValue;
            y = oriRotY [i] + RotateY * curveValue;
            z = oriRotZ [i] + RotateZ * curveValue;

            float new_x = x;
            float new_y = y;
            float new_z = z;

            newObjectPos         = new Vector3(new_x, new_y, new_z);
            displacedObjects [i] = newObjectPos;
        }
        if (!InvertedEffector)
        {
            for (int x = 0; x < originalObjects.Length; x++)
            {
                OriginalsPos.Set(OriginalX [x], OriginalY [x], OriginalZ [x]);
                if (Vector3.Distance(OriginalsPos, Effector.transform.position) <= EffectorDistance)
                {
                    float xLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.x, displacedObjects [x].x, EffectorRecoverySpeed * Time.deltaTime);
                    float yLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.y, displacedObjects [x].y, EffectorRecoverySpeed * Time.deltaTime);
                    float zLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.z, displacedObjects [x].z, EffectorRecoverySpeed * Time.deltaTime);
                    RotationVector.Set(xLerp, yLerp, zLerp);
                    movedObjects [x].eulerAngles = RotationVector;
                }
                else
                {
                    originalsLerper.Set(oriRotX [x], oriRotY [x], oriRotZ [x]);
                    float xLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.x, originalsLerper.x, EffectorRecoverySpeed * Time.deltaTime);
                    float yLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.y, originalsLerper.y, EffectorRecoverySpeed * Time.deltaTime);
                    float zLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.z, originalsLerper.z, EffectorRecoverySpeed * Time.deltaTime);
                    RotationVector.Set(xLerp, yLerp, zLerp);
                    movedObjects [x].eulerAngles = RotationVector;
                }
            }
        }
        else
        {
            for (int x = 0; x < originalObjects.Length; x++)
            {
                OriginalsPos.Set(OriginalX [x], OriginalY [x], OriginalZ [x]);
                if (Vector3.Distance(OriginalsPos, Effector.transform.position) > EffectorDistance)
                {
                    float xLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.x, displacedObjects [x].x, EffectorRecoverySpeed * Time.deltaTime);
                    float yLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.y, displacedObjects [x].y, EffectorRecoverySpeed * Time.deltaTime);
                    float zLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.z, displacedObjects [x].z, EffectorRecoverySpeed * Time.deltaTime);
                    RotationVector.Set(xLerp, yLerp, zLerp);
                    movedObjects [x].eulerAngles = RotationVector;
                }
                else
                {
                    originalsLerper.Set(oriRotX [x], oriRotY [x], oriRotZ [x]);
                    float xLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.x, originalsLerper.x, EffectorRecoverySpeed * Time.deltaTime);
                    float yLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.y, originalsLerper.y, EffectorRecoverySpeed * Time.deltaTime);
                    float zLerp = Mathf.LerpAngle(movedObjects [x].transform.eulerAngles.z, originalsLerper.z, EffectorRecoverySpeed * Time.deltaTime);
                    RotationVector.Set(xLerp, yLerp, zLerp);
                    movedObjects [x].eulerAngles = RotationVector;
                }
            }
        }
    }