void BallPitch() { if (ballState == BallState.Rolling) { //TODO: TOUCHPAD float pitchInput = TouchPadInput.GetAxis("Horizontal"); //TODO: KB&M //float pitchInput = Input.GetAxis("Horizontal"); if (pitchInput > 0) { xPitch = Mathf.MoveTowards(xPitch, 3.0f, xPitchSensitivity); } else if (pitchInput < 0) { xPitch = Mathf.MoveTowards(xPitch, -3.0f, xPitchSensitivity); } else { xPitch = Mathf.MoveTowards(xPitch, 0, xPitchSensitivity); } } }
void Update() { if (TouchPadInput.GetTouchesCount() > 0) { GameObject go = TouchPadInput.TouchedObject(); if (go == handler.gameObject) { touchingHandler = true; } } else { touchingHandler = false; } if (touchingHandler) { Vector3 touchPos = Camera.main.ScreenToViewportPoint(TouchPadInput.CurrentTouchPosition()); Vector2 handlerPos1 = Camera.main.WorldToViewportPoint(handler.position); float t = Time.deltaTime; float difference = touchPos.x - handlerPos1.x; if (difference > 0) { Vector3 rightLimit = new Vector3(bar.position.x + boundsBar.extents.x, bar.position.y, bar.position.z); float rightX = (rightLimit.x - handler.position.x); if (rightX > 0) { handler.transform.Translate(-t * handlerSpeed, 0f, 0f); } } else if (difference < 0) { Vector3 leftLimit = new Vector3(bar.position.x - boundsBar.extents.x, bar.position.y, bar.position.z); float leftX = (handler.position.x - leftLimit.x); if (leftX > 0) { handler.transform.Translate(t * handlerSpeed, 0f, 0f); } } } //Keep handler z axis the same as the bar's; Vector3 handlerPos = handler.position; Vector3 barPos = bar.position; handlerPos.y = barPos.y; handlerPos.z = barPos.z; handler.position = handlerPos; CheckDistance(); }
void ListenSlide() { if (!sliding) { bool turningLeft = false; bool turningRight = false; if (!moveLeft) { turningLeft = Input.GetKeyDown(KeyCode.LeftArrow) || TouchPadInput.GetButton("LeftArrow"); } if (!moveRight) { turningRight = Input.GetKeyDown(KeyCode.RightArrow) || TouchPadInput.GetButton("RightArrow"); } ; if (moveLeft) { if (moveLeft.isTouched()) { turningLeft = true; } } if (moveRight) { if (moveRight.isTouched()) { turningRight = true; } } if (turningLeft || turningRight) { toRotation = transform.rotation; if (turningLeft) { toRotation *= Quaternion.Euler(0f, 0f, separationAngle); } else if (turningRight) { toRotation *= Quaternion.Euler(0f, 0f, -separationAngle); } sliding = true; counter = 0; } } else { SlideBalls(SlideDirection.Right); } }
void BallJump() { if (ballState == BallState.Rolling) { bool inputJump = Input.GetKey(KeyCode.Space) || TouchPadInput.GetButton("Jump"); if (ballGrounded && inputJump) { rb.AddForce(Vector3.up * ballSettings.jumpForce, ForceMode.VelocityChange); } Color groundedRayColor = Color.red; Ray groundedRay = new Ray(transform.position, Vector3.down * bounds.extents.y); RaycastHit groundedHit; float adjustedextents = bounds.extents.y + 0.01f; if (Physics.Raycast(groundedRay, out groundedHit, adjustedextents)) { Lane lane = groundedHit.collider.gameObject.GetComponent <Lane>(); if (lane) { groundedRayColor = Color.green; ballGrounded = true; } } else { ballGrounded = false; } Debug.DrawRay(transform.position, Vector3.down * adjustedextents, groundedRayColor); } }
void SetBallRolling() { if (ballState == BallState.Idle) { GameObject b = TouchPadInput.TouchedObject(); if (b) { if (b.name == "Ball") { timeSinceTouchingBall += Time.deltaTime; } else { timeSinceTouchingBall = 0.0f; } if (timeSinceTouchingBall > MinTimeNeededToTouchBallAndSetRolling) { ballState = BallState.Rolling; timeSinceTouchingBall = 0.0f; } } else { timeSinceTouchingBall = 0.0f; } } else if (ballState == BallState.Rolling) { if (!currentWaypoint) { currentWaypoint = wpc.FirstWaypoint(); } else { currentWaypoint = wpc.NextWaypoint(currentWaypoint, transform.position); } Vector3 adjustedDirection; if (!currentWaypoint.IsLast) { adjustedDirection = new Vector3(currentWaypoint.transform.position.x - xPitch, currentWaypoint.transform.position.y, currentWaypoint.transform.position.z); } else { adjustedDirection = new Vector3(pinSet.transform.position.x - xPitch, pinSet.transform.position.y, pinSet.transform.position.z); } Vector3 direction = adjustedDirection - transform.position; rb.AddForce(direction * ballSettings.speed); ballState = BallState.Rolling; if (debugBall.ShowNextWaypointLine) { Debug.DrawRay(transform.position, direction, Color.green); } } }