// Update is called once per frame void Update() { if (allowMovement) { //Check for movement touch if (TouchInput.TouchIsValid(TouchDefines.movementTouchID)) { //Get the amount that that touch has moved in the last frame Touch movementTouch = Input.GetTouch(TouchDefines.movementTouchID); float platformMovement = TouchInput.GetDeltaTouchMovement(movementTouch).x *inputSensitivity; //Update target postion based on player input, clamp to our max screen bounds targetPosition += new Vector3(0f, 0f, platformMovement); targetPosition = MathUtils.ClampVec3(targetPosition, minPosition, maxPosition); } //Update postion using dampening so that movement is smooth Vector3.SmoothDamp(transform.position, targetPosition, ref currentVelocity, movementDampening, maxVelocity); blockRB.velocity = currentVelocity; } }
//Do Movement private void Update() { if (movementEnabled) { //Check for movement touch if (TouchInput.TouchIsValid(TouchDefines.movementTouchID)) { //Get the amount that that touch has moved in the last frame Touch movementTouch = Input.GetTouch(TouchDefines.movementTouchID); float shipMovement = TouchInput.GetDeltaTouchMovement(movementTouch).y *inputSensitivity; //Update target postion based on player input, clamp to our max screen bounds targetPostion += new Vector3(0, shipMovement, 0); targetPostion = MathUtils.ClampVec3(targetPostion, minPosition, maxPosition); } //Update postion using dampening so that movement is smooth transform.position = Vector3.SmoothDamp(transform.position, targetPostion, ref currentVelocity, movementDampening, maxYVelocity); } //Look at our target direction with an amount to look ahead (so we don't just look straight up) //and add some randomness to the rotation transform.LookAt(targetPostion + lookAheadDistance); }