Search Unity

Problem with rotation Clamp

Discussion in 'Scripting' started by Hotpockets26, May 6, 2019.

  1. Hotpockets26

    Hotpockets26

    Joined:
    Dec 16, 2017
    Posts:
    32
    I am trying to get my Orb (The white sphere in the picture below) to rotate around my player without rotating below the player. (I only want the Orb to rotate on the Blue and Red lines specified in the pictures below)

    The blue Axis is where I want it to rotate on the X and Z axis, and the red on the Y axis.
    sideview.PNG
    topview.PNG
    Sorry for the crude circles.....

    It works by rotating an invisible cube inside the player (The player is the blue cube with a little blue cube sticking out of it) and the white sphere is just a child of that invisible cube so it will follow its rotation. The invisible cube that is doing the rotating rotates toward the mouse position.

    The following is the only function in my script that has anything to do with the rotation.

    Code (CSharp):
    1.     void RightOrbRotation()
    2.     {
    3.  
    4.         Vector3 lookRot = hit.point - rotCube.transform.position; // Finds the distance from the orb and the mouse position, and then stores it in the lookRot variable
    5.         rotCube.transform.rotation = Quaternion.LookRotation(lookRot); // Makes the rotCubes forward face the mouse position.
    6.  
    7.         float rotMin = -180f;
    8.         float rotMax = 0f;
    9.         rotCube.transform.localEulerAngles = new Vector3(Mathf.Clamp(rotCube.transform.localEulerAngles.x, rotMin, rotMax), rotCube.transform.localEulerAngles.y, Mathf.Clamp(rotCube.transform.localEulerAngles.z, rotMin, rotMax));
    10.     }
    The only thing that in that function that is not created in the function is the
    Code (CSharp):
    1. hit.point
    which is just the point where the mouse is at, at that point in time.

    THE PROBLEM
    The rotation clamp causes the rotation of rotCube not to rotate at all on the X and Z axis (only rotates around Y). When what I want is it only to rotate on the Blue and Red lines that I specified in the picture above.

    Thanks, any help is greatly appreciated