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. Dismiss Notice

Resolved How to make a GameObject ignore an Impulse ?

Discussion in 'Cinemachine' started by Qhuhuit, May 23, 2021.

  1. Qhuhuit

    Qhuhuit

    Joined:
    Feb 17, 2018
    Posts:
    39
    Hello, thanks in advance for your help :)

    My game have a Cinemachine Virtual Camera with an Impulse Listener attached, which is working great for the screenshakes, but it also have some 3D objects, children to that camera, used as 3D UI objects.

    Those 3D objets children to the virtual camera are rendered by an Overlay Camera, similarly to the technique used in FPS to render the weapon for instance. It is working nicely.

    Problem is : they are affected by the impulse, but as they are used as UI objects, they should not! And as they are really close to the camera, they are shaking way more than the rest of the scene, so it is extremely noticeable!

    Do you have any idea how to make them not affected by the impulse while still being positioned in front of the camera, like a Camera screen space Canvas would be (but they're 3D objects) ?
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,494
    The easiest way I've found for stability near the camera is to make your 3D UI objects children of the camera transform. If this doesn't work with cinemachine for some reason (I have no experience with it), another approach is to make sure you're positioning elements after the other scripts are done ..so maybe could try moving related code to LateUpdate or customizing your execution order.
     
    Gregoryl likes this.
  3. Qhuhuit

    Qhuhuit

    Joined:
    Feb 17, 2018
    Posts:
    39
    Hey thanks for the reply, I found the solution!

    Making the objects children of the Main Camera (with the Cinemachine Brain component) is giving the intended result. They no longer shake with the impulse.
    When they were children of the Virtual Camera, which might actually not be moved by the impulse, they were shaking.

    The reason why I made them children of the VCam instead of the Main Cam is because the game have several VCam that are activated or disabled depending of the state of the game, so disabling the corresponding children made sense. But a quick script will do.
     
    adamgolden likes this.
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,494
    Okay - yeah I don't know anything about Virtual Camera etc. just meant like my3dUI.transform.SetParent(Camera.main.transform), but with cameras working differently I have no idea :( but maybe Camera.main transform position is still accurate so if u could reposition something relative to that after other stuff is done moving camera.. might work. Just what comes to mind, hopefully someone else has got a solution for u if not - good luck !

    Edit: good to hear it's working now :)
     
    Qhuhuit likes this.