Example #1
0
 void OnGUI()
 {
     if (showDebugInfo)
     {
         GUILayout.BeginVertical("box", GUILayout.MinWidth(275));
         {
             GUILayout.Label("Rigidbody Velocity: " + Rigidbody.velocity.ToString() + " | " + (Mathf.Round(Rigidbody.velocity.magnitude * 100) / 100));
             GUILayout.Label("MPH: " + ((Mathf.Round(Rigidbody.velocity.magnitude * 100) / 100) * 2.23694f));
             GUILayout.Label("Fixed UPS: " + 1 / Time.fixedDeltaTime);
             GUILayout.Label("FPS: " + (1 / fps).ToString("F2") + " (" + (1 / Time.deltaTime).ToString("F2") + ")");
             if (showCollisionInfo)
             {
                 GUILayout.Label(" Ground Normal: " + GroundNormal.ToString());
                 GUILayout.Label("         Angle: " + GroundNormalAngle);
                 GUILayout.Label("          Flag: " + isTouchingGround + " was " + wasTouchingGround);
                 GUILayout.Label("  Slope Normal: " + SteepSlopeNormal.ToString());
                 GUILayout.Label("         Angle: " + SteepSlopeNormalAngle);
                 GUILayout.Label("          Flag: " + IsTouchingSteepSlope + " on " + IsStandingOnSteepSlope);
                 GUILayout.Label("   Wall Normal: " + WallNormal.ToString());
                 GUILayout.Label("         Angle: " + WallNormalAngle);
                 GUILayout.Label("          Flag: " + IsTouchingWall);
                 GUILayout.Label("Ceiling Normal: " + CeilingNormal.ToString());
                 GUILayout.Label("         Angle: " + CeilingNormalAngle);
                 GUILayout.Label("          Flag: " + IsTouchingCeiling);
             }
         }
         GUILayout.EndVertical();
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (paused == true)
        {
            RaycastHit hit = new RaycastHit();
            Vector3    fwd = transform.TransformDirection(Vector3.forward);

            if (Input.GetKeyDown(KeyCode.Space))                //if Space is pressed do...
            {
                canMove = 0;
                //playerRigidbody.velocity = Vector3.zero;
                if (Physics.Raycast(transform.position, fwd, out hit, 3))                    //is there an object in front
                {
                    print("There is something in front of the object!");
                    print(hit.collider.gameObject.tag);
                    if (hit.collider.gameObject.tag == "wall")                       // if object you hit was a wall
                    {
                        print("hit a wall");
                        playerRigidbody.velocity = Vector3.zero;
                        Vector3 coor = new Vector3(hit.point.x, hit.point.y, hit.point.z); // raycast coordinates
                        transform.position = coor;                                         // to teleport

                        myPrevNormal = myNormal;
                        WallNormal wallNormal = hit.collider.gameObject.GetComponent <WallNormal> ();

                        myNormal = wallNormal.normal;

                        //transform.Rotate (Vector3.left * 90, Space.World); //rotate 90 degrees
                        Physics.gravity = myNormal * 10;                         // change gravity

                        // change rotation

                        if (myPrevNormal == Vector3.down)                           // PLANE 1
                        //transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z);
                        {
                            if (myNormal == Vector3.forward)
                            {
                                transform.Rotate(Vector3.left * 90, Space.World);
                            }
                            else if (myNormal == Vector3.back)
                            {
                                transform.Rotate(Vector3.right * 90, Space.World);
                            }
                            else if (myNormal == Vector3.left)
                            {
                                transform.Rotate(Vector3.back * 90, Space.World);
                            }
                            else if (myNormal == Vector3.right)
                            {
                                transform.Rotate(Vector3.forward * 90, Space.World);
                            }
                        }
                        else if (myPrevNormal == Vector3.forward)                             // PLANE 2
                        {
                            if (myNormal == Vector3.down)
                            {
                                transform.Rotate(Vector3.right * 90, Space.World);
                            }
                            else if (myNormal == Vector3.left)
                            {
                                transform.Rotate(Vector3.down * 90, Space.World);
                            }
                            else if (myNormal == Vector3.right)
                            {
                                transform.Rotate(Vector3.up * 90, Space.World);
                            }
                            else if (myNormal == Vector3.up)
                            {
                                transform.Rotate(Vector3.left * 90, Space.World);
                            }
                        }
                        else if (myPrevNormal == Vector3.left)                             // PLANE 3
                        {
                            if (myNormal == Vector3.down)
                            {
                                transform.Rotate(Vector3.forward * 90, Space.World);
                            }
                            else if (myNormal == Vector3.forward)
                            {
                                transform.Rotate(Vector3.up * 90, Space.World);
                            }
                            else if (myNormal == Vector3.back)
                            {
                                transform.Rotate(Vector3.down * 90, Space.World);
                            }
                            else if (myNormal == Vector3.up)
                            {
                                transform.Rotate(Vector3.back * 90, Space.World);
                            }
                        }
                        else if (myPrevNormal == Vector3.back)                             // PLANE 4
                        {
                            if (myNormal == Vector3.down)
                            {
                                transform.Rotate(Vector3.left * 90, Space.World);
                            }
                            else if (myNormal == Vector3.left)
                            {
                                transform.Rotate(Vector3.up * 90, Space.World);
                            }
                            else if (myNormal == Vector3.up)
                            {
                                transform.Rotate(Vector3.right * 90, Space.World);
                            }
                            else if (myNormal == Vector3.right)
                            {
                                transform.Rotate(Vector3.down * 90, Space.World);
                            }
                        }
                        else if (myPrevNormal == Vector3.right)                             // PLANE 5
                        {
                            if (myNormal == Vector3.down)
                            {
                                transform.Rotate(Vector3.back * 90, Space.World);
                            }
                            else if (myNormal == Vector3.forward)
                            {
                                transform.Rotate(Vector3.down * 90, Space.World);
                            }
                            else if (myNormal == Vector3.back)
                            {
                                transform.Rotate(Vector3.up * 90, Space.World);
                            }
                            else if (myNormal == Vector3.up)
                            {
                                transform.Rotate(Vector3.forward * 90, Space.World);
                            }
                        }
                        else if (myPrevNormal == Vector3.up)                             // Plane 6
                        {
                            if (myNormal == Vector3.forward)
                            {
                                transform.Rotate(Vector3.right * 90, Space.World);
                            }
                            else if (myNormal == Vector3.left)
                            {
                                transform.Rotate(Vector3.forward * 90, Space.World);
                            }
                            else if (myNormal == Vector3.back)
                            {
                                transform.Rotate(Vector3.left * 90, Space.World);
                            }
                            else if (myNormal == Vector3.right)
                            {
                                transform.Rotate(Vector3.back * 90, Space.World);
                            }
                        }
                    }
                }


                //change gravity
                canMove = 1;
            }

            if (canMove == 1)
            {
                if (Input.GetKey(KeyCode.D))
                {
                    if (myNormal == Vector3.right)
                    {
                        transform.Rotate(Vector3.left * 3f, Space.World);
                    }
                    if (myNormal == Vector3.left)
                    {
                        transform.Rotate(Vector3.right * 3f, Space.World);
                    }
                    if (myNormal == Vector3.up)
                    {
                        transform.Rotate(Vector3.down * 3f, Space.World);
                    }
                    if (myNormal == Vector3.down)
                    {
                        transform.Rotate(Vector3.up * 3f, Space.World);
                    }
                    if (myNormal == Vector3.forward)
                    {
                        transform.Rotate(Vector3.back * 3f, Space.World);
                    }
                    if (myNormal == Vector3.back)
                    {
                        transform.Rotate(Vector3.forward * 3f, Space.World);
                    }
                }
                if (Input.GetKey(KeyCode.A))
                {
                    if (myNormal == Vector3.right)
                    {
                        transform.Rotate(Vector3.right * 3f, Space.World);
                    }
                    if (myNormal == Vector3.left)
                    {
                        transform.Rotate(Vector3.left * 3f, Space.World);
                    }
                    if (myNormal == Vector3.up)
                    {
                        transform.Rotate(Vector3.up * 3f, Space.World);
                    }
                    if (myNormal == Vector3.down)
                    {
                        transform.Rotate(Vector3.down * 3f, Space.World);
                    }
                    if (myNormal == Vector3.forward)
                    {
                        transform.Rotate(Vector3.forward * 3f, Space.World);
                    }
                    if (myNormal == Vector3.back)
                    {
                        transform.Rotate(Vector3.back * 3f, Space.World);
                    }
                }

                float translation = Input.GetAxis("Vertical") * speed;
                float straffle    = Input.GetAxis("Horizontal") * speed;
                translation *= Time.deltaTime;
                straffle    *= Time.deltaTime;
                //playerRigidbody.AddForce(new Vector3(1000, 0, 1000));
                //transform.Translate (0, 0, translation);


                Animating(translation, straffle);
            }
        }
        //playerRigidBody.MovePosition(new Vector3(straffle, 0, translation));
        if (Input.GetKeyDown("escape"))
        {
            if (paused)
            {
                Time.timeScale = 0;
                Cursor.visible = true;
                pausePanel.SetActive(true);
                //camera.enabled = false;
                paused = false;
                print("Hello this is active");
            }
            else
            {
                Time.timeScale = 1;
                pausePanel.SetActive(false);
                //camera.enabled = true;
                Cursor.visible = false;
                paused         = true;
                print("noooooe");
            }
        }
    }