예제 #1
0
 void Update()
 {
     if (Input.GetKeyDown("space"))
     {
         Debug.Log($"SceneController.Update: space pressed");
         if (SphericalPaddle)
         {
             SphericalPaddle.Init();
         }
         if (PlanarPaddle)
         {
             PlanarPaddle.Init();
         }
         Ball.Init();
         // transform.position = sc.Rotate(0f, 0f).toCartesian;
         // SphericalPaddle.transform.position = sc.Rotate(0f, 0f).toCartesian;
     }
 }
예제 #2
0
    public void BallCollisionDispatcher(Collision other)
    {
        if (other.gameObject.tag == "SphericalPaddle")
        {
            ContactPoint contact = other.contacts[0];

            Debug.Log($"SceneController.BallCollisionDispatcher: sp.sc.toCartesian={SphericalPaddle.sc.toCartesian}");
            var paddleCenter = SphericalPaddle.PaddleCenterWorld();
            Debug.Log($"SceneController.BallCollisionDispatcher: paddleCenter={paddleCenter}");
            Debug.Log($"SceneController.BallCollisionDispatcher: contact - paddleCenter={contact.point - paddleCenter}");
            var   centerDelta     = contact.point - paddleCenter;
            var   boundingBox     = SphericalPaddle.GetComponent <BoxCollider>();
            float flingRatioWidth = centerDelta.x / boundingBox.size.x;

            var flingAngle = 45f * flingRatioWidth;
            Debug.Log($"flingRatioWidth={flingRatioWidth}, flingAngle={flingAngle}");
            Ball.transform.Rotate(0, 180f + flingAngle, 0);
            Debug.Log($"SceneController.BallCollisionDispatcher: transform.forward (pre)={transform.forward}, velocity (pre)={Ball.Velocity}");
            // Ball.transform.Rotate(45f, 90f, 0);
            // Ball.Velocity = transform.forward *= Ball.speed;
            Debug.Log($"SceneController.BallCollisionDispatcher: transform.forward (post)={transform.forward}, velocity (post)={Ball.Velocity}");
            // Ball.LastForward = Ball.transform.forward;
        }
        else if (other.gameObject.tag == "PlanarPaddle")
        {
            Debug.Log($"SceneController: planar paddle hit");
            PlanarPaddle.PlayPaddleHitAudio();
            ContactPoint contact     = other.contacts[0];
            var          centerDelta = contact.point - PlanarPaddle.transform.position;

            Debug.Log($"SC: centerDelta={centerDelta}, PlanarPaddle.Width={PlanarPaddle.Width}");
            var widthFactorAngle = 45f * centerDelta.x / PlanarPaddle.Width;
            Debug.Log($"SC: widthFactorAngle={widthFactorAngle}");
            // var widthAngleFactor =
            Ball.transform.Rotate(0, 180f + widthFactorAngle, 0);
            // Ball.LastForward = Ball.transform.forward;
        }
        else if (other.gameObject.tag == "SideWall")
        {
            var fwd = Ball.transform.forward;
            Ball.transform.forward = new Vector3(-fwd.x, fwd.y, fwd.z);
            // Ball.LastForward = Ball.transform.forward;
        }
    }
예제 #3
0
파일: Ball.cs 프로젝트: vt5491/SphereOut
    public void BoundaryHit(PlanarPaddle paddle, Vector3 hitPoint)
    {
        var fwd = transform.forward;

        transform.forward = new Vector3(fwd.x, fwd.y, -fwd.z);
    }