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

Black line appearing when using noise to shake screen.

Discussion in 'Cinemachine' started by derobile42, May 8, 2020.

  1. derobile42

    derobile42

    Joined:
    Apr 28, 2020
    Posts:
    4
    Hi there,

    I'm making a 2D top-down shooter and I want to add some screen shake when the player fires, when an enemy collides with the player, when a button is clicked, and so on. I've managed to get the screen shake when the enemy collides with the player by using the Impulse Listener extension thingy, and the screen shakes fine. It's just that whenever the screen shakes a black line appears across the tilemap.



    As you can see, the line is very apparent and I have no idea how to fix it. All of the art is 16x16.

    005B-500x500.png

    These are the settings for the Collision Impulse Source script on the slime enemy.

    I hope someone can help as the game doesn't feel right without the shake.

    Cheers
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi
    It may be caused by the 6D shake, because this adds positional and rotational noise to the camera along XYZ axes, and you may not want that in a 2D game. You probably want to have rotational noise along the depth axis (probably Z), and positional noise along X and Y axis.

    So, instead of the 6D shake, create a custom noise profile that will only add noise to the camera position along XY and camera rotation along Z.

    To create a custom noise, click on the gear icon and then New Noise Settings - see the attached CustomNoise.png. Save it.
    Find your saved custom noise profile, and edit it. For a simple example, see the attached NoiseSettings.png.

    Let us know if this helps. If not, I am happy to look at your project in more detail ;)
     

    Attached Files:

    Last edited: May 8, 2020
    Gregoryl likes this.
  3. derobile42

    derobile42

    Joined:
    Apr 28, 2020
    Posts:
    4
    This works perfectly! Thanks ever so much for the help. However, could you help me with one more thing if you don't mind?

    The other script for noise is called 'Input Source' which I think is callable from inside of a script, but I'm not too sure on how to actually call it. So how would I do this?

    Thanks.
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I am not sure what you mean. Could you be more specific?
    Would you like to generate an impulse from script?
     
  5. derobile42

    derobile42

    Joined:
    Apr 28, 2020
    Posts:
    4
    "Use the Cinemachine Impulse Source component to generate impulses on events that are not collisions or Collider triggers. This is a generic Impulse Source that exposes a family of GenerateImpulse() API methods. These methods generate impulses at the specified locations and with the specified velocities and strengths. Call these methods directly from your game logic, or use them with UnityEvents." -
    https://docs.unity3d.com/Packages/com.unity.cinemachine@2.2/manual/CinemachineImpulseSource.html

    It says you can call them directly from your game logic, which I'm guessing means script, but how would I do this. I tried GenerateImpulse() but the didn't work.
     
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Ah :)
    You can call it like this:
    Code (CSharp):
    1. var impulseSource = go.GetComponent<CinemachineImpulseSource>();
    2. impulseSource.GenerateImpulseAt(impulseSourcePosition, impulseDirection);
    3. // impulseSourcePosition and impulseDirection are both Vector3.
    Set go to a gameObject that has a CinemachineCollisionImpulseSource component. CinemachineCollisionImpulseSource is a child of CinemachineImpulseSource.


    There are several other overloads that you can call.
     
  7. derobile42

    derobile42

    Joined:
    Apr 28, 2020
    Posts:
    4
    I'll be sure to try this out tommorow morning, thanks a bunch.