Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mouse movement like Keyboard Movement

Discussion in 'Editor & General Support' started by Juan, Jul 8, 2009.

  1. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    I have a question.

    I have a character that you can control with the keyboard and with the mouse, the problem that i have is that when i control it with the keyboard it has acceleration and deceleration (wich is fine for me), i use
    Code (csharp):
    1. Input.GetAxis("Horizontal");
    but when i use the mouse with
    Code (csharp):
    1. Input.GetAxis("Mouse X");
    i don't have acceleration, the character moves exactli with the mouse, and i want some delay or acceleration, i want to behave like with the keyboard.

    Anyone have some thoughts?
    Thanks.

    Cheers.
     
  2. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Ok, i solved the problem!

    I used this line:
    Code (csharp):
    1.  
    2. CTR_HOR = Mathf.SmoothDamp(CTR_HOR, Input.GetAxis("Mouse X"),Velocity, smoothTime);
    3.  
    with this variables:
    Code (csharp):
    1.  
    2. private var smoothTime = 0.03;
    3. private var Velocity = 0.0;
    4.  
    For each axis each variable must be different, i mean that for the X Axis i have these that i wrote, and for the Y Axis i have another two variables, same value, different name, don't understand very well why, but at least it works in the editor.

    But only in the editor, and that's weird.

    I have a viewer in the GUI to see what is the value of the input Axsis X of the mouse.

    I get acceleretion/deceleration inside the editor when i test the game, but when i do a build for windows, the values of the x axis of the maouse are not the same that in the editor, and because of that the game is unplayable with the mouse.
    I tested locking the mouse cursor, but the result is the same.

    Help please.


    EDIT 1:
    When i use this:
    Code (csharp):
    1.  
    2. CTR_HOR = Input.GetAxis("Mouse X");
    3.  
    to move the mouse, the result is the same, is nearly unusable :p