Beispiel #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (move)                                                                                                                                      //this is set in wall. We could also just make this a coroutine that is ran on fixed udpate, but this works fine
        {
            myLavaWall.transform.position = Vector3.MoveTowards(myLavaWall.transform.position, myTargetPoints [currentPos].transform.position, speed); //move the wall towards the next chunk
            Vector3 dir = myTargetPoints [currentPos].transform.position - myLavaWall.transform.position;                                              //this is the vector that the wall is moving in, we use this to rotate towards this vector

            Vector3 newDir = Vector3.RotateTowards(myLavaWall.transform.forward, dir, rotSpeedModifier / (Vector3.Distance(myLavaWall.transform.position, myTargetPoints [currentPos].transform.position)), 0f);
            //this will rotate us towards the vector between our current position and our target position divided by the distance between the two, to make smoother rotations

            myLavaWall.rotation = Quaternion.LookRotation(newDir);
            //look at the vector calculated above


            if (myLavaWall.transform.position == myTargetPoints [currentPos].transform.position)                                                   //if we reach our target Lava Chunk
            {
                myTargetPoints [currentPos].EnableRenderer();                                                                                      //set the wall to Active
                if (myTargetPoints [currentPos].CheckPoint)                                                                                        //if this chunk is also a checkpoint,
                {
                    checkPoint = myTargetPoints [currentPos];                                                                                      //set it as lava wall checkpoint
                }
                if (currentPos < (myTargetPoints.Count - 1))                                                                                       //if we are not at the end of our list
                {
                    float curHeight = myTargetPoints [currentPos].transform.GetComponentInChildren <MeshFilter> ().mesh.bounds.max.y *scalingRate; //get the height of the mesh of this lava chunk
                    //ChunkDistance = Vector3.Distance (myTargetPoints [currentPos].transform.position, myTargetPoints [currentPos + 1].transform.position);
                    myLavaWall.localScale = new Vector3(myLavaWall.localScale.x, curHeight, myLavaWall.localScale.z);                              //set our lava walls scale to the height of the mesh of the chunk (ideally this would happen over time between the two poitns)
                    currentPos++;                                                                                                                  //set current pos(this current chunk we're operating on) to one position forward
                }
            }
        }
    }
    private void Update()
    {
        if (!Initialized)
        {
            return;
        }

        for (int i = 0; i < chunks.Length; i++)
        {
            chunkHeat[i] = Mathf.Lerp(chunkHeat[i], 0f, Time.deltaTime * heatDecreaseSpeed);

            LavaChunk chunk = chunks[i];
            chunk.Heat = chunkHeat[i];
            Vector4 hdrColor = Vector4.zero;
            hdrColor.x = baseColor.r;
            hdrColor.y = baseColor.g;
            hdrColor.z = baseColor.b;

            Color color = heatColor.Evaluate(chunkHeat[i]);
            hdrColor.x += color.r * 6;
            hdrColor.y += color.g * 6;
            hdrColor.z += color.b * 6;

            chunkPropertyBocks[i].SetColor("_EmissiveColor", hdrColor);
            chunk.Renderer.SetPropertyBlock(chunkPropertyBocks[i]);
        }

        for (int i = 0; i < fingertips.Length; i++)
        {
            Fingertip fingertip = fingertips[i];
            fingertip.Emission.enabled = (fingertip.Heat > 0.25f);
            fingertip.Heat             = Mathf.Lerp(fingertip.Heat, 0f, Time.deltaTime * heatDecreaseSpeed);
            fingertips[i] = fingertip;
        }

        for (int i = 0; i < lavaBubbles.Length; i++)
        {
            if (lavaBubbles[i].gameObject.activeSelf)
            {
                if (!lavaBubbles[i].enabled)
                {
                    lavaBubbles[i].gameObject.SetActive(false);
                }
            }
            else
            {
                if (Random.value > spawnOdds)
                {
                    if (!Physics.CheckSphere(lavaBubbles[i].transform.position, bubbleCheckRadius, chunkLayer))
                    {
                        lavaBubbles[i].gameObject.SetActive(true);
                    }
                }
            }
        }

        lavaScrollPos += scrollSpeed * Time.deltaTime;
        lavaMat.SetTextureOffset("_MainTex", lavaScrollPos);
    }
Beispiel #3
0
 public void StartLavaWall()
 {
     //This is ran by the relic, it just starts the lava wall
     checkPoint = myTargetPoints [0];  //I set my initial checkpoint to the first lava chunk
     myLavaWall.transform.position = myTargetPoints [0].transform.position; //set my position to the start position
     myLavaWall.LookAt (myTargetPoints [1].transform.position ); //look at my next position
     move = true; //start moving forward
 }
Beispiel #4
0
 public void StartLavaWall()
 {
     //This is ran by the relic, it just starts the lava wall
     checkPoint = myTargetPoints [0];                                       //I set my initial checkpoint to the first lava chunk
     myLavaWall.transform.position = myTargetPoints [0].transform.position; //set my position to the start position
     myLavaWall.LookAt(myTargetPoints [1].transform.position);              //look at my next position
     move = true;                                                           //start moving forward
 }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            LavaChunk lc = (LavaChunk)target;

            if (GUILayout.Button("Create"))
            {
                lc.Create();
            }
        }
    protected override void FixedUpdate()
    {
        if (!Initialized)
        {
            return;
        }

        base.FixedUpdate();

        for (int i = 0; i < fingers.Length; i++)
        {
            Transform finger    = fingers[i];
            Fingertip fingertip = fingertips[i];

            if (!finger.gameObject.activeSelf)
            {
                continue;
            }

            // If the finger is below the surface, ignore it
            float distToSurface = Vector3.Distance(finger.position, transform.position);
            if (distToSurface < SurfaceRadius)
            {
                continue;
            }

            for (int chunkIndex = 0; chunkIndex < chunks.Length; chunkIndex++)
            {
                LavaChunk chunk      = chunks[chunkIndex];
                Vector3   fingerPos  = finger.position;
                Vector3   closestPos = chunk.Collider.ClosestPoint(fingerPos);
                float     dist       = Vector3.Distance(fingerPos, closestPos);
                if (dist > fingerForceDist)
                {
                    continue;
                }

                // Add heat and force to the chunk
                Vector3 force = (closestPos - fingerPos).normalized * fingerPushForce;
                chunk.RigidBody.AddForceAtPosition(force, fingerPos, ForceMode.Force);
                chunkHeat[chunkIndex] = Mathf.Lerp(chunkHeat[chunkIndex], 1f, Time.fixedDeltaTime * heatIncreaseSpeed);
                chunkHeat[i]          = Mathf.Lerp(chunkHeat[i], 1f, Time.fixedDeltaTime * heatIncreaseSpeed * chunks[i].SubmergedAmount);
                // Add heat to the fingertip
                fingertip.Heat = Mathf.Lerp(fingertip.Heat, 1f, Time.fixedDeltaTime * heatIncreaseSpeed);
            }

            fingertips[i] = fingertip;
        }
    }
Beispiel #7
0
    public void SnapWall(LavaChunk CheckToAdd)
    {
        //This will snap the wall to a position. This is called by lava chunks if they are told to by a checkpoint.

        //when a player reaches a checkpoint
        for (int check = 0; check < myTargetPoints.Count; check++) {
            myTargetPoints [check].DisableRenderer (); //re disable all renderers
        }

        int nextPoint = 0;

        while (nextPoint < myTargetPoints.IndexOf (CheckToAdd)) { //move towards our new position
            myTargetPoints [nextPoint].EnableRenderer ();
            nextPoint++;
        }
        currentPos = myTargetPoints.IndexOf (CheckToAdd); //once we get to where we're going set it as current chunk
        myLavaWall.transform.position = CheckToAdd.transform.position; //move to current chunk
        checkPoint = CheckToAdd; //set it as a checkpoint
    }
Beispiel #8
0
    public void SnapWall(LavaChunk CheckToAdd)      //This will snap the wall to a position. This is called by lava chunks if they are told to by a checkpoint.
    //when a player reaches a checkpoint
    {
        for (int check = 0; check < myTargetPoints.Count; check++)
        {
            myTargetPoints [check].DisableRenderer();              //re disable all renderers
        }

        int nextPoint = 0;

        while (nextPoint < myTargetPoints.IndexOf(CheckToAdd))            //move towards our new position
        {
            myTargetPoints [nextPoint].EnableRenderer();
            nextPoint++;
        }
        currentPos = myTargetPoints.IndexOf(CheckToAdd);               //once we get to where we're going set it as current chunk
        myLavaWall.transform.position = CheckToAdd.transform.position; //move to current chunk
        checkPoint = CheckToAdd;                                       //set it as a checkpoint
    }
    public override void Initialize(Vector3 surfacePosition)
    {
        base.Initialize(surfacePosition);

        // Set up our bubbles
        for (int i = 0; i < lavaBubbles.Length; i++)
        {
            Vector3 randomPos = Random.onUnitSphere * bubbleDistance;
            lavaBubbles[i].transform.up = randomPos.normalized;
            lavaBubbles[i].transform.Rotate(-90f, 0f, 0f, Space.Self);
            lavaBubbles[i].transform.localPosition = randomPos;
            lavaBubbles[i].gameObject.SetActive(false);
        }

        chunkHeat          = new float[chunks.Length];
        chunkPropertyBocks = new MaterialPropertyBlock[chunks.Length];

        for (int i = 0; i < chunks.Length; i++)
        {
            LavaChunk chunk = chunks[i];
            chunk.RigidBody.AddForce(UnityEngine.Random.insideUnitSphere * initialImpulseForce, ForceMode.Force);
            chunkPropertyBocks[i] = new MaterialPropertyBlock();
            chunk.OnCollision    += OnCollision;
        }

        fingertips = new Fingertip[fingers.Length];
        for (int i = 0; i < fingertips.Length; i++)
        {
            Fingertip ft = new Fingertip();
            ft.Heat  = 0;
            ft.Block = new MaterialPropertyBlock();
            //ft.Rigidbody = fingers[i].GetComponentInChildren<Rigidbody>();
            ft.Renderer         = fingers[i].GetComponentInChildren <MeshRenderer>();
            ft.Particles        = fingers[i].GetComponentInChildren <ParticleSystem>();
            ft.Emission         = ft.Particles.emission;
            ft.Emission.enabled = false;
            fingertips[i]       = ft;
        }
    }
Beispiel #10
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (move) { //this is set in wall. We could also just make this a coroutine that is ran on fixed udpate, but this works fine
            myLavaWall.transform.position = Vector3.MoveTowards (myLavaWall.transform.position, myTargetPoints [currentPos].transform.position, speed); //move the wall towards the next chunk
            Vector3 dir = myTargetPoints [currentPos].transform.position - myLavaWall.transform.position; //this is the vector that the wall is moving in, we use this to rotate towards this vector

            Vector3 newDir = Vector3.RotateTowards (myLavaWall.transform.forward, dir, rotSpeedModifier / (Vector3.Distance (myLavaWall.transform.position, myTargetPoints [currentPos].transform.position)), 0f);
                //this will rotate us towards the vector between our current position and our target position divided by the distance between the two, to make smoother rotations

            myLavaWall.rotation = Quaternion.LookRotation (newDir);
                //look at the vector calculated above

            if (myLavaWall.transform.position == myTargetPoints [currentPos].transform.position) { //if we reach our target Lava Chunk
                myTargetPoints [currentPos].EnableRenderer (); //set the wall to Active
                if (myTargetPoints [currentPos].CheckPoint) { //if this chunk is also a checkpoint,
                    checkPoint = myTargetPoints [currentPos]; //set it as lava wall checkpoint
                }
                if (currentPos < (myTargetPoints.Count - 1)) { //if we are not at the end of our list
                    float curHeight = myTargetPoints [currentPos].transform.GetComponentInChildren<MeshFilter> ().mesh.bounds.max.y * scalingRate; //get the height of the mesh of this lava chunk
                    //ChunkDistance = Vector3.Distance (myTargetPoints [currentPos].transform.position, myTargetPoints [currentPos + 1].transform.position);
                    myLavaWall.localScale = new Vector3 (myLavaWall.localScale.x, curHeight, myLavaWall.localScale.z); //set our lava walls scale to the height of the mesh of the chunk (ideally this would happen over time between the two poitns)
                    currentPos++; //set current pos(this current chunk we're operating on) to one position forward
                }
            }
        }
    }