void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Slider")) { Slider s = collision.gameObject.GetComponent<Slider>(); if (s != null) { int tsign = s.getSign(); if (tsign == 0) { sign *= -1; } else { sign = tsign; direction = s.movementDimension; speed = s.angularSpeed; } } playSound(); } else if (collision.gameObject.CompareTag("Wedge")) { //Debug.Log("Hit Wedge"); WedgeBehavior wb = collision.gameObject.GetComponentInParent<WedgeBehavior>(); if (collision.collider.Equals(wb.bottom)) { sign *= wb.sign; direction = direction == 1 ? 0 : 1; //Debug.Log("Bottom"); } else { sign = -sign; //Debug.Log("side"); } playSound(); } else if (collision.gameObject.CompareTag("Barrier")) { sign *= -1; playSound(); } Vector3 startPos = gameObject.transform.position; SphericalCoordinates sc = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); sc.FromCartesian(startPos); elevationAngle = sc.elevation; polarAngle = sc.polar; activeAdjustment = true; }
void Update() { if (activeAdjustment) { Vector3 currentPos = gameObject.transform.position; SphericalCoordinates sc = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); sc.loopPolar = true; sc.FromCartesian(currentPos); //sc.SetRadius(radius); float change = sign * speed * Time.deltaTime; if (direction == 0) { sc.RotatePolarAngle(change); gameObject.transform.position = sc.toCartesian; } else { sc.RotateElevationAngle(change); gameObject.transform.position = sc.toCartesian; } } if (Input.GetButton("R1")) { mainCam.SetActive(false); ballCam.SetActive(true); } else { mainCam.SetActive(true); ballCam.SetActive(false); } }
// Use this for initialization void Start() { startPosition = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, minPolar*Mathf.Deg2Rad, maxPolar * Mathf.Deg2Rad, minElevation * Mathf.Deg2Rad, maxElevation * Mathf.Deg2Rad); startPosition.loopPolar = false; startPosition.FromCartesian(transform.position); curPosition = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, minPolar * Mathf.Deg2Rad, maxPolar * Mathf.Deg2Rad, minElevation * Mathf.Deg2Rad, maxElevation * Mathf.Deg2Rad); curPosition.loopPolar = false; curPosition.FromCartesian(transform.position); sliders = GameObject.FindGameObjectsWithTag("Slider"); }