Ejemplo n.º 1
0
 //private Vector3 Previous_position;
 void CheckInputs()
 {
     if (Input.GetMouseButton(0))
     {
         //None of the UI Elements are selected.
         //So, check if the Puck is selected.
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit, Mathf.Infinity))
         {
             Debug.DrawLine(Puck.Get().rigidbody.position, hit.point, Color.cyan);
             if (hit.collider.name.Contains("Puck"))
             {
                 m_MouseStartPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Depth);
                 if (!easyslidehack)
                 {
                     EasySlide     = m_MouseStartPos;
                     easyslidehack = true;
                 }
                 m_IsPuckSelected = true;
                 var lock_puck = new Vector3(hit.point.x,
                                             Puck.Get().transform.position.y,
                                             hit.point.z - CorrectionforMouse);
                 lock_puck.x = Mathf.Clamp(lock_puck.x, -0.37f, 0.37f);
                 Puck.Get().rigidbody.position = lock_puck;
                 //Previous_position = lock_puck;
             }
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         this.Pucklaunch();
     }
 }
Ejemplo n.º 2
0
    void OnTriggerExit(Collider other)
    {
        //Hackey way to reset puck if it gone out of the table
        //This is not final we have to fix the PUCK going out of table bug.
        if (other.name.Contains("Puck"))
        {
            Debug.LogError("PUCK gone out of table, \nVelocity: " + other.rigidbody.velocity.magnitude);
            Debug.LogError("\nForce: " + other.rigidbody.velocity + "resetting it (it's a HACK, dont forget to Fix!!)");

            Puck.Get().ResetPuck();
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        if (Properties.isPopUpShown)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (!Properties.S_CantakeInputs)
        {
            if (m_IsPuckSelected && m_LineCrossed && easyslidehack)
            {
                Debug.Log("releasing the puck");

                Vector3 m_MouseEndPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Depth);
                Vector3 force         = (m_MouseEndPos - EasySlide);
                var     Zforce        = force.magnitude / Time.deltaTime;
                force = new Vector3(-force.x, 0, -Zforce);
                Debug.Log(force);
                if (force.magnitude > 0.3f)
                {
                    Puck.Get().LaunchPuck(force);
                }
                else
                {
                    Puck.Get().rigidbody.velocity = Vector3.zero;
                    Puck.Get().ResetPuck();
                }
                m_IsPuckSelected = false;
                easyslidehack    = false;
            }
            return;
        }
        this.CheckInputs();
        if (Puck.Get() != null)
        {
            if ((Puck.Get().transform.position.x > 0.15f || Puck.Get().transform.position.x < -0.15f) &&
                m_LineCrossed == false &&
                Input.GetMouseButtonUp(0) &&
                Puck.Get().transform.position.z < 1.90f)
            {
                StartCoroutine("Follow_camera");
            }
        }
    }
Ejemplo n.º 4
0
 private void Pucklaunch()
 {
     if (m_IsPuckSelected == true)
     {
         Vector3 m_MouseEndPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Depth);
         Vector3 force         = (m_MouseEndPos - m_MouseStartPos);
         var     Zforce        = force.magnitude / Time.deltaTime;
         force = new Vector3(-force.x, 0, -Zforce);
         //Debug.Log(force);
         if (force.magnitude > 0.3f)
         {
             Puck.Get().LaunchPuck(force);
         }
         else
         {
             Puck.Get().rigidbody.velocity = Vector3.zero;
         }
         m_IsPuckSelected = false;
         easyslidehack    = false;
     }
 }
Ejemplo n.º 5
0
    void FixedUpdate()
    {
        //have we moved more than our minimum extent?
        Vector3 movementThisStep     = myRigidbody.position - previousPosition;
        float   movementSqrMagnitude = movementThisStep.sqrMagnitude;

        if (movementSqrMagnitude > sqrMinimumExtent)
        {
            float      movementMagnitude = Mathf.Sqrt(movementSqrMagnitude);
            RaycastHit hitInfo           = new RaycastHit();

            //check for obstructions we might have missed
            if (Physics.Raycast(previousPosition, movementThisStep, out hitInfo, movementMagnitude * 2.0f, layerMask.value))
            {
                //myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
                Puck.Get().RegisterHit(hitInfo.transform.gameObject.name);
            }
        }

        previousPosition = myRigidbody.position;
    }