hi,
i have created a script that changes the way the navigation works in unity. i thought everything worked until i tested it thoroughly. However when i rotated it down or rotated it up. next time i moved forward or backwards i would slightly bounce. my code is shown below if anyone has an idea please let me know?
if(Input.GetButton("Fire2")) //will only activate when user hold second mouse button down
{
// Read the mouse input axis
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
//Debug.Log("b");
}
//replicate vrml navigation
else if(Input.GetButton("Fire1"))
{
//print("button pressed");
ray = Input.mousePosition; //makes ray = to the mouse position
mouseVelocity = ray - lastRay;
count2++;
print("button pressed"+count2);
//print(mouseVelocity.y+"mvy"); //
//print(movementSensitivity+"ms");
if(mouseVelocity.y>movementSensitivity)
{
dir = "Up";
}
else if(mouseVelocity.y<-movementSensitivity)
{
dir = "Down";
}
//~ else if(dir=="Up"|| dir=="Down" mouseVelocity.y )
//~ {
//~ }
if(dir=="Up")
{
//works kind of collision works only goes one direction at moment now it works
CharacterController controller = GetComponent<CharacterController>(); //attaches the character controller to the variable controller
//sets the direction that the person is facing that they will only go in the way they are facing
//moveDirection = transform.TransformDirection(new Vector3(0, 0, mouseSpeed));
moveDirection = transform.TransformDirection(new Vector3(0, 0, mouseSpeed));
controller.Move(moveDirection * Time.deltaTime);
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
//allows the user to use the rotation angle they used in there rotation if they used one
rotationY = ClampAngle (rotationY, minimumY, maximumY);
//this applys it to the y rotation if uses it so it keeps the rotation used
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
//applys the rotation to the user
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if(dir == "Down")
{
//works kind of collision works only goes one direction at moment now it works
CharacterController controller = GetComponent<CharacterController>(); //attaches the character controller to the variable
//sets the direction that the person is facing that they will only go in the way they are facing
moveDirection = transform.TransformDirection(new Vector3(0, 0, -mouseSpeed));
controller.Move(moveDirection * Time.deltaTime);
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
//allows the user to use the rotation angle they used in there rotation if they used one
rotationY = ClampAngle (rotationY, minimumY, maximumY);
//this applys it to the y rotation if uses it so it keeps the rotation used
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
//applys the rotation to the user
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if(dir != "Down" || dir != "Up")
{
dir = "None";
}
//dir = "None";
//}
//print("mouse veleocity vector: "+mouseVelocity+", Movement Y direction:"+dir);
lastRay = ray;
}