Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

mouse to sensitive, moving to fast

Discussion in 'Editor & General Support' started by Arno1975, Sep 19, 2018.

  1. Arno1975

    Arno1975

    Joined:
    Aug 14, 2013
    Posts:
    43
    i am moving this object with the following code...
    this code is attached to a parent of the camera..

    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (Input.GetMouseButtonDown(2))
    4.             GetMouse = false;
    5.         if (Input.GetMouseButtonUp(2))
    6.             GetMouse = true;
    7.         // if (Input.GetKeyDown(KeyCode.LeftShift))
    8.         //    CameraDisabled = !CameraDisabled;
    9.  
    10.         if (!GetMouse)
    11.  
    12.       {
    13.             float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
    14.             Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
    15.             transform.position = new Vector3(pos_move.x, transform.position.y , pos_move.z );
    16.  
    17.  
    18.         }
    19.     }
    but if i move the mouse slightly i already get a big movement, but i can't figure out how to add in the sensitivity.

    please help.
     
  2. Arno1975

    Arno1975

    Joined:
    Aug 14, 2013
    Posts:
    43
    i used the lerp function:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraPan : MonoBehaviour
    6. {
    7.  
    8.     public bool GetMouse = true;
    9.     private Vector3 newPosition;
    10.  
    11.     //private Transform cam;
    12.     void Awake()
    13.     {
    14.         newPosition = transform.position;
    15.     }
    16.     void Update()
    17.     {
    18.         if (Input.GetMouseButtonDown(2))
    19.      
    20.              GetMouse = false;
    21.          if (Input.GetMouseButtonUp(2))
    22.              GetMouse = true;
    23.    
    24.           if (!GetMouse)
    25.         {
    26.             PositionChanging();
    27.         }
    28.  
    29.     }
    30.      void PositionChanging()
    31.       {
    32.             float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
    33.             Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
    34.             newPosition = new Vector3(pos_move.x, transform.position.y , pos_move.z );
    35.  
    36.             transform.position = Vector3.Lerp(transform.position,newPosition, Time.deltaTime);
    37.  
    38.  
    39.         }
    40.  
    41.  
    42.  
    43. }
    not exactly what i wanted..wanted a drag...but this will do..