Search Unity

Rotating rigidbody

Discussion in 'Game Design' started by JKornet, Sep 30, 2018.

  1. JKornet

    JKornet

    Joined:
    Aug 30, 2018
    Posts:
    3
    I am rotating an 3D object with camera (as child) and a rigidbody with Mouse and keyboard. I am using the following codesnippet:
    Code (CSharp):
    1. private void Update()
    2.     {
    3.  
    4.         float rh = Input.GetAxisRaw("Mouse X");
    5.         float rv = Input.GetAxisRaw("Mouse Y");
    6.         float rx = Input.GetAxisRaw("Roll");
    7.  
    8.         rotInput = new Vector3(rv, rh, rx);
    9.         Thrust();  //Move forward and backward
    10.  
    11.     }
    12.  
    13.     private void FixedUpdate()
    14.     {
    15.         Moving.MoveInput(rotInput);
    16.     }
    I can move the 3D object (and the camera) with the mouse, but when I look to the left or to the right, the camera is tilting a little diagonal. I want to rotate with the mouse just like a 6DOF game, but with a rigidbody (not with transform.euler....). Does anyone know a solution so that the camera moves exactly in order with the mouse (without tilting diagonal)?

    I change the code to:
    Code (CSharp):
    1. void moveWithMouse()
    2. {
    3.     moveCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), arrowMouseSpeed);
    4. }
    5.  
    6. void moveCamera(float horizontal, float verticle, float moveSpeed)
    7.     {
    8.         mouseX = horizontal;
    9.         mouseY = -verticle;
    10.  
    11.     rotY += mouseX * moveSpeed;
    12.     rotX += -mouseY * moveSpeed;
    13.     roll += Input.GetAxis("Roll");
    14.     rotInput = new Vector3(rotY, rotX, roll);
    15.     Debug.Log("rotInput" + rotInput);
    16.  
    17. }
    But now it keeps rotating and I can't stop it. I still use a ridigbody. Is there a solution, so the mouse works correct and the camera stop rotating when I stop moving the mouse?
     
  2. Donniel_Lewis

    Donniel_Lewis

    Joined:
    Dec 6, 2014
    Posts:
    9
    This post doesn't belong here.
     
    Joe-Censored likes this.