Mouse Camera Rotation Problem

Hi,

I’m trying to get my camera to rotate around the target object while the mouse is held down, however, it won’t detect the movement of the mouse on the x-axis. For reference, flt_speed is set at 1.

    private void Camera_Orbit ( float flt_speed )
    {
        print ( "OUTER TEST" );
        if ( Input.GetAxis ( "Mouse X" ) <= -1f )
        {
            print ( "TEST" );
            go_CameraTarget.transform.Rotate ( 0f, flt_speed * Time.deltaTime, 0f );
        }
    }

Any help is greatly appreciated,

Jonathan Palmer

Most axes will return from -1 to +1

Therefore your if predicate will never fire.

Instead you may want to multiply the returned value from Input.GetAxis() by your flt_speed and use that to rotate things.

Input.GetAxis docs say that a delta mouse axis isn’t necessarily -1…1 range because it’s multiplied by the axis sensitivity.

However, it would be a good idea to Debug.Log(Input.GetAxis ( “Mouse X” ).toString()) so you can see what the actual value is, and testing whether it’s <= -1 seems unlikely to be what you want.

If you want to move the target based on the amount of mouse movement, then you should be multiplying the amount of movement by Input.GetAxis and not by Time.deltaTime. And in that case you probably don’t need any threshold on Input.GetAxis at all, although I suppose you could still consider having a “dead zone” if the movement looks too jittery.

If you want the thing to move at constant speed while the mouse button is held down, then I’m not sure why you’re trying to detect the mouse movement at all.