void OnTriggerEnter(Collider other) {
		touchBendingPlayerListener tempPlayerVars = other.GetComponent<touchBendingPlayerListener>();
		// register touch only if collider has the touchBendingPlayerListener script attached and enabled
		if( tempPlayerVars != null && tempPlayerVars.enabled) {
			// no other touch event registered
			if (!touched) {
				//register gameobject ID
				Player_ID = other.GetInstanceID();
				
				Destroy(myRenderer.material);
				
				PlayerVars = tempPlayerVars;
				Player_Direction = PlayerVars.Player_Direction;
				Player_Speed = PlayerVars.Player_Speed;
				intialTouchForce = Player_Speed;
				
				// instantiate mat
				myRenderer.material = touchBendingMaterial;
				myRenderer.material.SetVector("_TouchBendingPosition", new Vector4(myTransform.position.x, myTransform.position.y, myTransform.position.z, 0f) );
				
				axis = PlayerVars.Player_Direction;
				// rotate by 90
				axis = Quaternion.Euler(0,90,0) * axis;
				
				timer = 0.0f;
				touched = true;
				left = false;
				targetTouchBending = 1.0f;
				touchBending = targetTouchBending;
				finished = false;
			}
			else {
				/// 2nd+ touch: we simply drop the first registered collision
				if ( doubletouched == true ) {
					SwapTouchBending ();	
				}
				//register gameobject ID
				Player1_ID = other.GetInstanceID();
				
				PlayerVars1 = tempPlayerVars;
				Player_Direction1 = PlayerVars1.Player_Direction;
				Player_Speed1 = PlayerVars1.Player_Speed;
				intialTouchForce1 = Player_Speed1;
				
				axis1 = Player_Direction1;
				// rotate by 90
				axis1 = Quaternion.Euler(0,90,0) * axis1;
				
				timer1 = 0.0f;
				left1 = false;
				targetTouchBending1 = 1.0f;
				touchBending1 = targetTouchBending1;
				finished1 = false;
				lerptime = duration - timer;
				doubletouched = true;
			}
		}
	}
 public void SwapTouchBending()
 {
     this.Player_ID          = this.Player1_ID;
     this.PlayerVars         = this.PlayerVars1;
     this.Player_Direction   = this.Player_Direction1;
     this.Player_Speed       = this.Player_Speed1;
     this.intialTouchForce   = this.intialTouchForce1;
     this.touchBending       = this.touchBending1;
     this.targetTouchBending = this.targetTouchBending1;
     this.easingControl      = this.easingControl1;
     this.left     = this.left1;
     this.finished = this.finished1;
     this.axis     = this.axis1;
     this.timer    = this.timer1;
 }
 public void SwapTouchBending()
 {
     Player_ID          = Player1_ID;
     PlayerVars         = PlayerVars1;
     Player_Direction   = Player_Direction1;
     Player_Speed       = Player_Speed1;
     intialTouchForce   = intialTouchForce1;
     touchBending       = touchBending1;
     targetTouchBending = targetTouchBending1;
     easingControl      = easingControl1;
     left     = left1;
     finished = finished1;
     axis     = axis1;
     timer    = timer1;
 }
    private void OnTriggerEnter(Collider other)
    {
        touchBendingPlayerListener component = other.GetComponent <touchBendingPlayerListener>();

        if (component != null && component.enabled)
        {
            if (!this.touched)
            {
                this.Player_ID          = other.GetInstanceID();
                this.PlayerVars         = component;
                this.Player_Direction   = this.PlayerVars.Player_Direction;
                this.Player_Speed       = this.PlayerVars.Player_Speed;
                this.intialTouchForce   = this.Player_Speed;
                this.axis               = this.PlayerVars.Player_Direction;
                this.axis               = Quaternion.Euler(0f, 90f, 0f) * this.axis;
                this.timer              = 0f;
                this.touched            = true;
                this.left               = false;
                this.targetTouchBending = 1f;
                this.touchBending       = this.targetTouchBending;
                this.finished           = false;
            }
            else
            {
                if (this.doubletouched)
                {
                    this.SwapTouchBending();
                }
                this.Player1_ID          = other.GetInstanceID();
                this.PlayerVars1         = component;
                this.Player_Direction1   = this.PlayerVars1.Player_Direction;
                this.Player_Speed1       = this.PlayerVars1.Player_Speed;
                this.intialTouchForce1   = this.Player_Speed1;
                this.axis1               = this.Player_Direction1;
                this.axis1               = Quaternion.Euler(0f, 90f, 0f) * this.axis1;
                this.timer1              = 0f;
                this.left1               = false;
                this.targetTouchBending1 = 1f;
                this.touchBending1       = this.targetTouchBending1;
                this.finished1           = false;
                this.lerptime            = this.duration - this.timer;
                this.doubletouched       = true;
            }
        }
    }
Exemplo n.º 5
0
    void OnTriggerEnter(Collider other)
    {
        touchBendingPlayerListener tempPlayerVars = other.GetComponent <touchBendingPlayerListener>();

        // register touch only if collider has the touchBendingPlayerListener script attached and enabled
        if (tempPlayerVars != null && tempPlayerVars.enabled)
        {
            touches.Add(new touch()
            {
                go               = other.transform.gameObject,
                playerId         = other.GetInstanceID(),
                playerDirection  = tempPlayerVars.Player_Direction,
                intialTouchForce = tempPlayerVars.Player_Speed,
                // rotate axis by 90
                axis      = Quaternion.Euler(0, 90, 0) * tempPlayerVars.Player_Direction,
                timer     = 0.0f,
                timerLeft = 0.0f,
                left      = false,
            });
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        touchBendingPlayerListener component = other.GetComponent <touchBendingPlayerListener>();
        bool flag = false;

        if ((this.bush || this.bush2) && this.IsStructure(other))
        {
            if (this.bush)
            {
                if (flag)
                {
                    this.bush.DespawnBush();
                }
                else
                {
                    this.bush.CutDownReal();
                }
            }
            if (this.bush2)
            {
                if (flag)
                {
                    this.bush2.DespawnBush();
                }
                else
                {
                    this.bush2.CutDown();
                }
            }
            return;
        }
        if (component != null && component.enabled)
        {
            if (!this.touched)
            {
                this.Player_ID          = other.GetInstanceID();
                this.PlayerVars         = component;
                this.Player_Direction   = this.PlayerVars.Player_Direction;
                this.Player_Speed       = this.PlayerVars.Player_Speed;
                this.intialTouchForce   = this.Player_Speed;
                this.axis               = this.PlayerVars.Player_Direction;
                this.axis               = Quaternion.Euler(0f, 90f, 0f) * this.axis;
                this.timer              = 0f;
                this.touched            = true;
                this.left               = false;
                this.targetTouchBending = 1f;
                this.touchBending       = this.targetTouchBending;
                this.finished           = false;
            }
            else
            {
                if (this.doubletouched)
                {
                    this.SwapTouchBending();
                }
                this.Player1_ID          = other.GetInstanceID();
                this.PlayerVars1         = component;
                this.Player_Direction1   = this.PlayerVars1.Player_Direction;
                this.Player_Speed1       = this.PlayerVars1.Player_Speed;
                this.intialTouchForce1   = this.Player_Speed1;
                this.axis1               = this.Player_Direction1;
                this.axis1               = Quaternion.Euler(0f, 90f, 0f) * this.axis1;
                this.timer1              = 0f;
                this.left1               = false;
                this.targetTouchBending1 = 1f;
                this.touchBending1       = this.targetTouchBending1;
                this.finished1           = false;
                this.lerptime            = this.duration - this.timer;
                this.doubletouched       = true;
            }
        }
    }
Exemplo n.º 7
0
    void Update()
    {
        registeredTouches = touches.Count;

        //	Reset
        finalMatrix     = Matrix4x4.identity;
        finalRotation   = Quaternion.identity;
        finalTouchForce = Vector4.zero;

        //	Handles touches
        if (registeredTouches > 0)
        {
            resetted = false;
            touch temp;
            for (int i = 0; i < registeredTouches; i++)
            {
                temp = touches[i];
                //	Update Player vars
                touchBendingPlayerListener tempPlayerVars = temp.go.GetComponent <touchBendingPlayerListener>();

                //	Reset Animation if it has ended
                if (temp.timer >= duration)
                {
                    if (temp.left == true)
                    {
                        touchToRemove = i;
                    }
                }

                //	Bounce Animation
                else
                {
                    //temp.easingControl = Mathf.Lerp( Mathf.Sin(temp.timer * 10.0f / duration) / (temp.timer + 1.25f) * 8.0f, target, Mathf.Sqrt( temp.timer / duration ) );
                    temp.easingControl = Mathf.Lerp(Mathf.Sin(temp.timer * 10.0f / duration) / (temp.timer + 1.25f) * 8.0f, 0.0f, Mathf.Clamp01(temp.timer / duration));
                }

                if (temp.left == true)
                {
                    // timerLeft = 0 --> player is outside the trigger
                    temp.timerLeft = Mathf.Clamp01(temp.timerLeft - Time.deltaTime * duration);
                }
                else
                {
                    // timerLeft = 1 --> player is inside the trigger
                    temp.timerLeft = Mathf.Clamp01(temp.timerLeft + Time.deltaTime * duration);
                }

                //	Set timer according to Player_Speed if player is inside the trigger
                temp.timer += Time.deltaTime * Mathf.Lerp(1.0f, tempPlayerVars.Player_Speed, temp.timerLeft);

                touches[i] = temp;
                Quaternion rotation = Quaternion.Euler(temp.axis * (temp.intialTouchForce * bendability * temp.easingControl));
                finalRotation = finalRotation * rotation;

                //	Calculate extra force // faster to do it componentwise istead of new Vector4()
                finalTouchForce.x += temp.playerDirection.x * temp.easingControl;
                finalTouchForce.y += temp.playerDirection.y * temp.easingControl;
                finalTouchForce.z += temp.playerDirection.z * temp.easingControl;
                finalTouchForce.w += tempPlayerVars.Player_Speed * temp.easingControl * disturbance;
                //finalTouchForce.w += temp.playerSpeed * temp.easingControl * disturbance; //temp.playerSpeed
            }

            //	Set rotation and extra force
            finalMatrix.SetTRS(Vector3.zero, finalRotation, Vector3.one);
            TouchMaterialBlock.SetMatrix(RotMatrixPID, finalMatrix);
            TouchMaterialBlock.SetVector(TouchBendingForcePID, finalTouchForce);
            m_Renderer.SetPropertyBlock(TouchMaterialBlock);

            //	Remove touch from list
            if (touchToRemove != -1)
            {
                touches.RemoveAt(touchToRemove);
                touchToRemove = -1;
            }
        }
        else if (!resetted)
        {
            //	Remove PropertyBlock
            resetted = true;
            TouchMaterialBlock.Clear();
            m_Renderer.SetPropertyBlock(TouchMaterialBlock);
        }
    }
    void OnTriggerEnter(Collider other)
    {
        touchBendingPlayerListener tempPlayerVars = other.GetComponent <touchBendingPlayerListener>();

        // register touch only if collider has the touchBendingPlayerListener script attached and enabled
        if (tempPlayerVars != null && tempPlayerVars.enabled)
        {
            // no other touch event registered
            if (!touched)
            {
                //register gameobject ID
                Player_ID = other.GetInstanceID();

                Destroy(myRenderer.material);

                PlayerVars       = tempPlayerVars;
                Player_Direction = PlayerVars.Player_Direction;
                Player_Speed     = PlayerVars.Player_Speed;
                intialTouchForce = Player_Speed;

                // instantiate mat
                myRenderer.material = touchBendingMaterial;
                myRenderer.material.SetVector("_TouchBendingPosition", new Vector4(myTransform.position.x, myTransform.position.y, myTransform.position.z, 0f));

                axis = PlayerVars.Player_Direction;
                // rotate by 90
                axis = Quaternion.Euler(0, 90, 0) * axis;

                timer              = 0.0f;
                touched            = true;
                left               = false;
                targetTouchBending = 1.0f;
                touchBending       = targetTouchBending;
                finished           = false;
            }
            else
            {
                /// 2nd+ touch: we simply drop the first registered collision
                if (doubletouched == true)
                {
                    SwapTouchBending();
                }
                //register gameobject ID
                Player1_ID = other.GetInstanceID();

                PlayerVars1       = tempPlayerVars;
                Player_Direction1 = PlayerVars1.Player_Direction;
                Player_Speed1     = PlayerVars1.Player_Speed;
                intialTouchForce1 = Player_Speed1;

                axis1 = Player_Direction1;
                // rotate by 90
                axis1 = Quaternion.Euler(0, 90, 0) * axis1;

                timer1 = 0.0f;
                left1  = false;
                targetTouchBending1 = 1.0f;
                touchBending1       = targetTouchBending1;
                finished1           = false;
                lerptime            = duration - timer;
                doubletouched       = true;
            }
        }
    }
 public void SwapTouchBending()
 {
     this.Player_ID = this.Player1_ID;
     this.PlayerVars = this.PlayerVars1;
     this.Player_Direction = this.Player_Direction1;
     this.Player_Speed = this.Player_Speed1;
     this.intialTouchForce = this.intialTouchForce1;
     this.touchBending = this.touchBending1;
     this.targetTouchBending = this.targetTouchBending1;
     this.easingControl = this.easingControl1;
     this.left = this.left1;
     this.finished = this.finished1;
     this.axis = this.axis1;
     this.timer = this.timer1;
 }
 private void OnTriggerEnter(Collider other)
 {
     touchBendingPlayerListener component = other.GetComponent<touchBendingPlayerListener>();
     if (component != null && component.enabled)
     {
         if (!this.touched)
         {
             this.Player_ID = other.GetInstanceID();
             this.PlayerVars = component;
             this.Player_Direction = this.PlayerVars.Player_Direction;
             this.Player_Speed = this.PlayerVars.Player_Speed;
             this.intialTouchForce = this.Player_Speed;
             this.axis = this.PlayerVars.Player_Direction;
             this.axis = Quaternion.Euler(0f, 90f, 0f) * this.axis;
             this.timer = 0f;
             this.touched = true;
             this.left = false;
             this.targetTouchBending = 1f;
             this.touchBending = this.targetTouchBending;
             this.finished = false;
         }
         else
         {
             if (this.doubletouched)
             {
                 this.SwapTouchBending();
             }
             this.Player1_ID = other.GetInstanceID();
             this.PlayerVars1 = component;
             this.Player_Direction1 = this.PlayerVars1.Player_Direction;
             this.Player_Speed1 = this.PlayerVars1.Player_Speed;
             this.intialTouchForce1 = this.Player_Speed1;
             this.axis1 = this.Player_Direction1;
             this.axis1 = Quaternion.Euler(0f, 90f, 0f) * this.axis1;
             this.timer1 = 0f;
             this.left1 = false;
             this.targetTouchBending1 = 1f;
             this.touchBending1 = this.targetTouchBending1;
             this.finished1 = false;
             this.lerptime = this.duration - this.timer;
             this.doubletouched = true;
         }
     }
 }
	public void SwapTouchBending () {
		Player_ID = Player1_ID;
		PlayerVars = PlayerVars1;
		Player_Direction = Player_Direction1;
		Player_Speed = Player_Speed1;
		intialTouchForce = intialTouchForce1;
		touchBending = touchBending1;
		targetTouchBending = targetTouchBending1;
		easingControl = easingControl1;
		left = left1;
		finished = finished1;
		axis = axis1;
		timer = timer1;
	}