Search Unity

How do i set sensitivity for offset mouse movement?

Discussion in 'Scripting' started by hizral, May 4, 2015.

  1. hizral

    hizral

    Joined:
    Apr 27, 2010
    Posts:
    568
    Hello there.

    I have this script for my mouse movement. The movement is offset and I would like to know how do i set sensitivity for the movement so when i move my mouse cursor the object that move will move a lot faster than my mouse cursor.

    below here is my script.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Public_MouseMove : MonoBehaviour {
    5.  
    6.     public Transform tGimbal;
    7.     public Transform tFollow;
    8.     public float fSensitivity;
    9.  
    10.     public Vector3 vMousePos;
    11.     public Vector3 vWorldPos;
    12.     public Vector3 vLastPos;
    13.     public Vector3 vNewDelta;
    14.     public Vector3 vScreenPos;
    15.  
    16.     public bool isPressed;
    17.    
    18.     public Camera cTouchCam;
    19.     RaycastHit rHit;
    20.     Ray rRay;
    21.     // Use this for initialization
    22.     void Start ()
    23.     {
    24.    
    25.     }
    26.    
    27.     // Update is called once per frame
    28.     void Update ()
    29.     {
    30.         tGimbal.LookAt (tFollow);
    31.  
    32.         rRay = cTouchCam.ScreenPointToRay (Input.mousePosition);
    33.  
    34.         if (Input.GetMouseButton (0))
    35.         {
    36.             if (Physics.Raycast (rRay, out rHit, 100))
    37.             {
    38.                 if (rHit.collider.tag == "tMouseMovement")
    39.                 {
    40.                     isPressed = true;  
    41.                 }
    42.             }
    43.         }
    44.         else
    45.         {
    46.             isPressed = false;
    47.         }
    48.  
    49.         if (isPressed)
    50.         {
    51.             vMousePos = new Vector3 (vNewDelta.x + Input.mousePosition.x, vNewDelta.y + Input.mousePosition.y, vNewDelta.z);
    52.             vWorldPos = cTouchCam.ScreenToWorldPoint (vMousePos);
    53.             //vWorldPos -= vLastPos;
    54.             tFollow.position = vWorldPos;
    55.  
    56.            
    57.         }
    58.         else
    59.         {
    60.             vScreenPos = cTouchCam.WorldToScreenPoint (tFollow.position);
    61.             vNewDelta = new Vector3 (vScreenPos.x - Input.mousePosition.x , vScreenPos.y - Input.mousePosition.y, vScreenPos.z);
    62.             //vLastPos = vWorldPos;
    63.         }
    64.     }
    65. }
    66.