예제 #1
0
 private void ShuffleSpline(IRageSpline rageSpline, float shuffleAmount)
 {
     for (int i = 0; i < rageSpline.GetPointCount(); i++)
     {
         Vector3 point = rageSpline.GetPosition(i);
         point += new Vector3(Random.Range(shuffleAmount * -0.5f, shuffleAmount * 0.5f), Random.Range(shuffleAmount * -0.5f, shuffleAmount * 0.5f), 0f);
         rageSpline.SetPoint(i, point);
     }
 }
예제 #2
0
    public void CreateNewLandscape()
    {
        //transform.position = new Vector3(0f,0f,0f);

        pointGapWidth = (startX2 - startX) / (float)(pointCount - 1);

        rageSpline.ClearPoints();
        for (int i = 0; i < pointCount; i++)
        {
            float x = startX + (float)i * pointGapWidth;
            curSteepness = steepness + x * 0.00001f;
            rageSpline.AddPointWorldSpace(i, GetNewLandscapePoint(x), transform.right * pointGapWidth * 0.33f);
        }

        rageSpline.SetPoint(0, new Vector3(rageSpline.GetPosition(0).x, 0f, 0f));
        rageSpline.SetPoint(1, new Vector3(rageSpline.GetPosition(1).x, 0f, 0f));

        rageSpline.RefreshMesh();
    }
예제 #3
0
    void Awake()
    {
        // Store the instance of RageSpline to avoid calling it every frame for speed/convenience.
        // Cast to IRageSpline for cleaner API access
        rageSpline = GetComponent(typeof(RageSpline)) as IRageSpline;

        // Array for movement target positions per control point
        targetPositions = new Vector3[rageSpline.GetPointCount()];

        // Store the original control point positions
        originalPositions = new Vector3[rageSpline.GetPointCount()];

        for (int index = 0; index < rageSpline.GetPointCount(); index++)
        {
            originalPositions[index] = rageSpline.GetPosition(index);
        }
    }
예제 #4
0
    void Awake()
    {
        // Store the instance of RageSpline to avoid calling it every frame for speed/convenience.
        // Cast to IRageSpline for cleaner API access
        rageSpline = GetComponent(typeof(RageSpline)) as IRageSpline;

        // Array for movement Target positions per control point
        targetPositions = new Vector3[rageSpline.GetPointCount()];

        // Store the original control point positions
        originalPositions = new Vector3[rageSpline.GetPointCount()];

        for (int index = 0; index < rageSpline.GetPointCount(); index++)
        {
            originalPositions[index] = rageSpline.GetPosition(index);
        }
    }
예제 #5
0
    void Update()
    {
        timeSinceLastShake += Time.deltaTime;

        // Is it time for a new shake?
        if (timeSinceLastShake > currentShakeGap)
        {
            // Iterate through all the control points
            for (int index = 0; index < rageSpline.GetPointCount(); index++)
            {
                // Randomise a new shake vector
                Vector3 shakeVector = new Vector3(
                    Random.Range(-0.5f * shakeSizeInNormalSpace.x, 0.5f * shakeSizeInNormalSpace.x),
                    Random.Range(-0.5f * shakeSizeInNormalSpace.y, 0.5f * shakeSizeInNormalSpace.y),
                    0f);

                // Get normal and tangent for the control point. We will shake along the normal.
                Vector3 normal  = rageSpline.GetNormal(index);
                Vector3 tangent = Vector3.Cross(normal, Camera.main.transform.forward);

                // Set a new position for the control point
                targetPositions[index] = originalPositions[index] + shakeVector.x * tangent + shakeVector.y * normal;
            }

            // When is the next new shake?
            currentShakeGap    = Random.Range(minFrameGap, maxFrameGap);
            timeSinceLastShake = 0f;
        }
        else
        {
            // Iterate through all the control points
            for (int index = 0; index < rageSpline.GetPointCount(); index++)
            {
                // Interpolate toward Target positions with Vector3.Lerp()
                Vector3 currentPosition = rageSpline.GetPosition(index);
                rageSpline.SetPoint(index, Vector3.Lerp(currentPosition, targetPositions[index], Time.deltaTime * (1f / easing)));
            }
        }

        // Finally refresh the visible mesh
        rageSpline.RefreshMesh(true, true, false);

        // Faster version (possible artifacts)
        //rageSpline.RefreshMesh(false, false, false);
    }
예제 #6
0
파일: Shake.cs 프로젝트: migreva/CocoBounce
    void Update()
    {
        // Iterate through all the control points
        for (int index = 0; index < rageSpline.GetPointCount(); index++)
        {
            // Get the current control point position in localspace coordinates
            Vector3 oldPosition = rageSpline.GetPosition(index);

            // Randomise a new shake vector
            Vector3 shakeVector = new Vector3(
                Random.Range(-0.5f * shakeSize.x, 0.5f * shakeSize.x),
                Random.Range(-0.5f * shakeSize.y, 0.5f * shakeSize.y),
                0f);

            // Set a new position for the control point
            rageSpline.SetPoint(index, oldPosition + shakeVector);
        }

        // Finally refresh the visible mesh
        rageSpline.RefreshMesh(true, true, true);

        // Faster version (possible artifacts)
        // rageSpline.RefreshMesh(false, false, false);
    }
예제 #7
0
    // This gets all the control positions from the original rageSpline (which we are editing) and moves our GUI accordingly
    public void refreshEditorGUI()
    {
        for (int index = 0; index < rageSpline.GetPointCount(); index++)
        {
            // We are just moving the GameObject transform. No need to access the API.
            controlPoints[index].transform.position    = rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -1f);
            inControlPoints[index].transform.position  = rageSpline.GetInControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f);
            outControlPoints[index].transform.position = rageSpline.GetOutControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f);

            // Put the object transform center where the control point is
            handleLines[index].transform.position = rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -0.5f);

            // Set both ends of the line where the underlying in/out ctrlpoint handles are
            handleLines[index].SetPointWorldSpace(0, rageSpline.GetInControlPositionWorldSpace(index));
            handleLines[index].SetPointWorldSpace(1, rageSpline.GetOutControlPositionWorldSpace(index));

            // Handles pointing to the middle to make a straight line
            handleLines[index].SetOutControlPositionPointSpace(0, (rageSpline.GetPosition(index) - rageSpline.GetOutControlPosition(index)) * 0.25f);
            handleLines[index].SetOutControlPositionPointSpace(1, (rageSpline.GetInControlPosition(index) - rageSpline.GetPosition(index)) * 0.25f);

            // Since we modified the spline, we need to refresh the mesh
            handleLines[index].RefreshMesh(false, true, false);
        }
    }
예제 #8
0
 private void ShuffleSpline(IRageSpline rageSpline, float shuffleAmount)
 {
     for (int i = 0; i < rageSpline.GetPointCount(); i++)
     {
         Vector3 point = rageSpline.GetPosition(i);
         point += new Vector3(Random.Range(shuffleAmount*-0.5f, shuffleAmount*0.5f), Random.Range(shuffleAmount*-0.5f, shuffleAmount*0.5f), 0f);
         rageSpline.SetPoint(i, point);
     }
 }