void Update() { if (tenser == null) { return; } // Calculate how much past the threshold the tenser is, clamp the excess to 1 float tenserFactor = Mathf.Min((tenser.transform.position.y - tenserThreshold) / tenserMax, 1); // Check if the tenser is above the threshold, if so then check rope tension: if (tenserFactor > 0) { // Calculate current tension as ratio between current and rest length, then subtract 1 to center it at zero. float tension = rope.CalculateLength() / rope.restLength - 1; // Use tension to interpolate between colors: float lerpFactor = (tension - minTension) / (maxTension - minTension); localMaterial.color = Color.Lerp(normalColor, tensionColor, lerpFactor * tenserFactor); } else { localMaterial.color = normalColor; } }
private void Update() { float strain = rope.CalculateLength() / rope.RestLength; actualTensity = strain; SetNumberParticle(); if (!activeRopeChange) { return; } isTenseForJump = (strain > stretchForJump) ? true : false; isTenseForAirMove = (strain > stretchForAirMove) ? true : false; isTenseForAdd = (strain > stretchAdd) ? true : false; isTenseForLess = (strain < stretchRemove) ? true : false; //si l'un ou les 2 son gripped, ne pas modifier la rope ModifyRope(strain); ShortCutRope(strain); //essai de raccourcir la rope lors du grip SetupLengtheningRope(); //essai de setup le ralongage la rope en place lorsque le grip est fini et que les 2 joueurs sont grounded (ou groundedException) LenghteningRope(); //ralonge la rope ! }
/// <summary> /// Move the player /// </summary> private void ProcessInput() { // Process jump, check jump again just in case if ((jump || (player.GetButtonDown("Jump") && grounded)) && haveBox == false && !gameManager.tutUnpausing) { Vector3 yVel = new Vector3(rb.velocity.x, 0, rb.velocity.z); rb.velocity = yVel + Vector3.up * jumpSpeed; midJump = true; // Play jump sound audioManager.PlayJump(playerId); if (jumpParticles) { jumpParticles.Play(); } } // Process movement if (thrown && canMove) { // decreased input when in the air moveVector = rb.velocity; //Debug.Log("Thrown"); Debug.Log(transform.rotation); } // Apply velocity to the rigidbody here moveVector.y = rb.velocity.y; //if(rope.CalculateLength() > rope.RestLength) //{ //Debug.Log("Rope"); //} if ((baby.ropeChanging || grandma.ropeChanging || rope.CalculateLength() > rope.RestLength) && !grounded && !thrown && !midJump) { // Do nothing to the velocity, the baby is being pulled in the air //Debug.Log("What"); } else { if (canMove) { rb.velocity = moveVector; } else { rb.velocity = new Vector3(0, rb.velocity.y, 0); } } if (haveBox && playerId == 1) { rb.velocity = new Vector3(0, rb.velocity.y, 0); } // Process rotation if ((moveVector.x != 0 || moveVector.z != 0) && allowRotate) { float z_angle = Mathf.Atan2(movementDir.x, movementDir.z) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0, z_angle, 0)); } // Process pick up box or baby if (player.GetButtonDown("Pick") || (player.GetButtonUp("Pick") && (haveBox || haveBbcat))) { grab = true; } else { grab = false; } // Check m_TutorialPause state // To avoid confliction of two actions if (grab && !bePicked && !gameManager.GetTutorialPause()) { pickupCont.PickupPressed(); } // Process drop baby cat, both can drop if (player.GetButtonDown("Drop")) { gmaPickupCont.Drop(); } // Process baby meow meow = player.GetButtonDown("Meow"); if (meow) { meowSound.Play(); } if (restart) { gameManager.RestartLevel(); } }