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

Orthographic camera movement using mouse for RTS game

Discussion in 'Scripting' started by rahulkamra, Aug 16, 2013.

  1. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    Hi,

    I am very new to unity as well as 3D programming. I am trying to move the camera using mouse but the movement is not perfect . I guess i am doing some calculation mistakes but not able to figure it out. My Script :



    Code (csharp):
    1.  
    2.         if (Input.GetMouseButtonDown(0))
    3.         {
    4.             mouseDownPoint =Input.mousePosition;
    5.         }
    6.  
    7.  
    8.         if (Input.GetMouseButtonUp(0))
    9.         {
    10.             mouseDownPoint = Vector3.zero ;
    11.         }
    12.  
    13.  
    14.         if (!mouseDownPoint.Equals(Vector3.zero))
    15.         {
    16.             Vector3 diff = mouseDownPoint - Input.mousePosition;
    17.             Camera.mainCamera.transform.Translate(diff);
    18.             mouseDownPoint = Input.mousePosition;
    19.             return;
    20.         }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    that really doesn't tell us anything... how is it working? how do you want it to work? describe the actual problem you are getting...
     
  3. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
  4. rahulkamra

    rahulkamra

    Joined:
    Aug 16, 2013
    Posts:
    15
    I just want my camera to move with the same speed as my mouse cursor , With the above implementation camera moves at a higher speed than the mouse