Ejemplo n.º 1
0
    // public void PaddleHit(Vector3 angleDelta) {
    //     // Debug.Log($"Ball.PaddleHit: entered");

    //     // velocity.x = -velocity.x;
    //     // velocity.z = -velocity.z;
    //     // Debug.Log($"Ball.PaddleHit: magnitude vel.pre={Velocity.magnitude}");
    //     // Velocity = new Vector3(
    //     //     (Velocity.x + angleDelta.x),
    //     //     Velocity.y + angleDelta.y,
    //     //     -(Velocity.z + angleDelta.z));
    //     // Debug.Log($"Ball.PaddleHit: magnitude vel.post={Velocity.magnitude}");
    //     Velocity = new Vector3(
    //         (-Velocity.x + angleDelta.x),
    //         -(Velocity.y + angleDelta.y),
    //         -(Velocity.z + angleDelta.z));
    // }

    // Send the ball back towards the game center
    public void BoundaryHit(SphericalPaddle paddle, Vector3 hitPoint)
    {
        dir      = -1 * (transform.position - paddle.Pivot.position).normalized;
        Velocity = dir *= Speed;

        transform.forward = dir;
        // Utils.DrawLine(hitPoint, hitPoint + 3.0f * Velocity, Color.green, 60);
        // Utils.DrawLine(hitPoint, hitPoint + 3.0f * Velocity, Color.green, 60);
        // transform.Rotate(0, 180f + flingAngle, 0);
        Utils.DrawLine(transform.position, transform.position + 3.0f * Velocity, Color.green, 60);
    }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
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;
        }
    }