How to disable my mouse to turn right

Hello everyone, I need help with coding and I’ve no idea how to do it. Basically, I don’t want my “First Person Controller” (standart assets/character controller) to be able to turn right. Now I understand it works as X and Y but is there any way I can disable for it to turn right, and only turn left (X-wise. I want Y to stay as it is)

I’ve seen and tried changing “Minimum X, Maximum X” but it doesn’t work. It always lets player turn right and left.

Setting minimumX and maximumX will have no effect because they're not used in your script anywhere. You need to add a clamp statement to the rotationX in the same way that you've clamped rotationY between minimumY and maximumY

–

Thank you for your comment, I've edited my code and it's "half-working" right now but still not the result I want. Mouse doesn't turn right when we don't turn left. But if mouse turns left, we can go right. Till the point in the beginning, where mouse can't turn right. :/

–

1 Answer

1

You will need to ignore either positive or negative input from the Input.GetAxis(). So change line 27 to either this:

float inputX = Input.GetAxis("Mouse X");
if (inputX > 0.0f)
    transform.Rotate(0.0f, inputX * sensitivityX, 0.0f);

or

float inputX = Input.GetAxis("Mouse X");
if (inputX < 0.0f)
    transform.Rotate(0.0f, inputX * sensitivityX, 0.0f);

I don't why the code I provided would have given you an error. As for your problem, is it an issue with orientation? That is, if you rotate something 180 degrees, left rotation becomes right rotation.

–

Hello! I'm using "MouseXandY" since it lets mouse to go on both X and Y planes. (looking up-down and right-left) I've deleted the other MouseY and MouseX cause when they're ticked in "Inspector" part they only used their plane. (only X or only Y) About Rotate, error is CS0103: The name 'Rotate' does not exist in the current context. If you can help me, please do. I will surely give credits too :>

–

It should have been 'transform.Rotate'. I fixed my code. But I unsure that it will be the solution. As I said, part of left/right turning depends on the frame of reference.

–

And it is working now... I can't thank you enough. I CAN'T THANK YOU ENOUGH!

–