void Update() { if (Time.timeScale == 0) { return; } flashTimer.Update(Time.deltaTime); float forceRatio = 0; if (useLeftHand) { gameCont.RegisterForce(_GlobalVariables.LEFT_INDEX, (int)_GlobalVariables.leftForce); forceRatio = Mathf.Min(_GlobalVariables.leftForce / (_GlobalVariables.maxGripStrength[0] * 1.05f), 1f); } else { gameCont.RegisterForce(_GlobalVariables.RIGHT_INDEX, (int)_GlobalVariables.rightForce); forceRatio = Mathf.Min(_GlobalVariables.rightForce / (_GlobalVariables.maxGripStrength[1] * 1.05f), 1f); } float adjustedHeightRange = viewPort.y - spriteHeight; float targetHeight = forceRatio * adjustedHeightRange - adjustedHeightRange / 2; Vector2 target = new Vector2(xPosition, targetHeight); transform.position = Vector2.Lerp(transform.position, target, 0.1f); }
/// <summary> /// Used by outside entities to apply a grip input switch /// </summary> //public void SwitchControls() //{ //switchHands = !switchHands; //} /// <summary> /// Method <c>Update</c> called by engine every update cycle. Used to check for keypresses or /// other input and update player status variables accordingly. /// </summary> public void Update() { //skip update loop if paused if (Time.timeScale == 0) { return; } //read percentage of maximum force input that is currently applied from arduino sensor //We multiply denominator of proportion by 0.5 to ceil at half force for more precision requirements leftForceRatio = Mathf.Min(_GlobalVariables.leftForce / (_GlobalVariables.maxGripStrength[0] * 0.5f), 1f); rightForceRatio = Mathf.Min(_GlobalVariables.rightForce / (_GlobalVariables.maxGripStrength[1] * 0.5f), 1f); if (!hasReachedFloor) { float appliedForce = _GlobalVariables.leftForce + _GlobalVariables.rightForce; if (appliedForce <= _GlobalVariables.maxGripStrength.Sum(m => m) * FLOOR_PERCENTAGE) { hasReachedFloor = true; } else { return; } } //if the switch trigger has been set then we just switch the values for left and right hand grips //if (switchHands) //{ //float temp = leftForceRatio; //leftForceRatio = rightForceRatio; //rightForceRatio = temp; //} if (leftForceRatio >= ACCELERATION_PERCENTAGE && rightForceRatio >= ACCELERATION_PERCENTAGE) { float accelerationRatio = (leftForceRatio + rightForceRatio) / 2; velocity = accelerationRatio * velocityConversionRate; //velocity is proportional to left force float xComponent = velocity * Mathf.Sin(angle * Mathf.Deg2Rad); float yComponent = velocity * Mathf.Cos(angle * Mathf.Deg2Rad); rb.velocity = new Vector2(-1 * xComponent, yComponent); } else { rb.velocity = new Vector2(0, 0); float angleAdditionLeft = leftForceRatio * angleConversionRate; angle += angleAdditionLeft; float angleAdditionRight = rightForceRatio * angleConversionRate; angle -= angleAdditionRight; angle %= 360; transform.eulerAngles = new Vector3(0, 0, angle); } //if (gameContScript.GetStage() < 2) //MazeSmartFeedbackProcessor.PlayerTurn(angleAddition); //else //MazeSmartFeedbackProcessor.SwitchedPlayerTurn(angleAddition); Vector3 old = transform.position; transform.position = new Vector3(old.x, old.y, -2); //update the loop timer flashTimer.Update(Time.deltaTime); }