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

Bug Strange movements

Discussion in 'Scripting' started by artux87, Dec 17, 2022.

  1. artux87

    artux87

    Joined:
    Dec 27, 2021
    Posts:
    2
    Hi,

    I'm new in Unity, I create a scope that you can move with mouse and change inclination with Q and E key.

    It works, but when I test intensely after i stop move mouse or press key, it continues to move here the code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class RotateWithMouse : MonoBehaviour
    4. {
    5.  
    6.     public float Speed = 0.05f;
    7.     private Vector3 currentEulerAngle;
    8.     private GameObject Bubble;
    9.  
    10.     void Start() {
    11.         Cursor.visible = false;
    12.         Bubble = GameObject.Find("Bubble");
    13.     }
    14.    
    15.     void Update() {
    16.  
    17.         currentEulerAngle = transform.eulerAngles;
    18.  
    19.         transform.eulerAngles += Speed * new Vector3(0, Input.GetAxis("Mouse X"), 0);
    20.         transform.eulerAngles += Speed * new Vector3( -Input.GetAxis("Mouse Y"), 0, 0);
    21.  
    22.         if(Input.GetKey(KeyCode.E)) {
    23.             transform.eulerAngles += Speed * new Vector3(0, 0, -1);
    24.             Bubble.transform.localPosition += new Vector3(0, -0.0025f, 0);
    25.         }
    26.  
    27.         if(Input.GetKey(KeyCode.Q)) {
    28.             transform.eulerAngles += Speed * new Vector3(0, 0, +1);
    29.             Bubble.transform.localPosition += new Vector3(0, +0.0025f, 0);
    30.         }
    31.     }
    32. }
    Here results:


    I honestly don't know what to do to fix it.

    Do you have in past similar issue? (maybe is near 0 vector ex. 1e-27 and continue moving not stop?)
     
  2. artux87

    artux87

    Joined:
    Dec 27, 2021
    Posts:
    2
    Solved, there is a rigid body so there is a "inertian tension rotation" i remove it (unnecessary in my case) and it works