How to do Camera Shake with Cinemachine!

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น •

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +26

    Cinemachine Camera Shake! I couldn't find a simple tutorial on it so I'm hoping this will help someone!
    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php

    • @aarondelgado3421
      @aarondelgado3421 4 ปีที่แล้ว

      It doesn't make sense to love your own comment.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +5

      Why not? I use the hearts to highlight comments, naturally I want to highlight my comment with helpful links.

    • @Funnypoison671
      @Funnypoison671 4 ปีที่แล้ว

      Codemoney I was on your discord sever but I seen some stuff and left but I'm thinking of coming back your a good coder and it's easy to understand and I like it when you fast-forward to get the boring part out of the vid just watching you type and the greatest part is when I get to see the code

    • @hemantbisht7079
      @hemantbisht7079 3 ปีที่แล้ว +1

      Hey code monkey can u please help me out.
      I did same steps you did but i am getting an error "cinemachinevirtualcamera does not contain a definition for basicmultichannelperlin".
      I have alredy included using cinemachine.
      Please help me out i am not gettin it
      I am using cinemachine 2d camera.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      @@hemantbisht7079 Sound like you didnt add the noise extension

  • @jonordona9733
    @jonordona9733 4 ปีที่แล้ว +44

    If anyone is trying to apply this to 3D and is using a FreeLook Camera, just be aware that the Free Look Camera is actually just three Virtual Cameras, each one on the bottom, mid, and top rig. To access them I've had to use a for loop and using the GetRig method, which accepts an integer (Just use 0,1,2), then, you can access the Perlin component of each rig and apply what's explained in the tutorial.
    By the way, these tutorials are amazing! Straight to the point, no wasting the viewers' time. Thanks!

    • @everythingonit3159
      @everythingonit3159 2 ปีที่แล้ว +1

      Thanks for the tip, it worked for me.

    • @ignatiuswallmeyer9838
      @ignatiuswallmeyer9838 2 ปีที่แล้ว

      @@everythingonit3159 Yeah, doing mine now:)

    • @AdamMarshall-fw6no
      @AdamMarshall-fw6no ปีที่แล้ว

      @@ignatiuswallmeyer9838 yea i was wondering how to work with a free look thank you

  • @erosjagatpulagana6403
    @erosjagatpulagana6403 4 ปีที่แล้ว +6

    i'm aware that there are still few Cinemachine tutorial out there, especially on youtube, so thank you so much for adding this! Wish i could have this long ago, but it's better than nothing, and still helpful to help my current project

  • @jeongbalsancat
    @jeongbalsancat 4 ปีที่แล้ว +1

    I've never even thought about using Cinemachine.. this will make my side scrolling game look sooo polished. thanks so much!

  • @algs5483
    @algs5483 4 ปีที่แล้ว

    Geez, thank you a ton. I'm participating a game jam and needed a camera shake, but I was using Cinemachine and couldnt find a way to shake my camera with Cinemachine, but then this video appeard. Thank you!

  • @pierredalaya444
    @pierredalaya444 3 ปีที่แล้ว +7

    You can also use the cinemachine Impulse component instead of writing code

  • @ChimpanzeeUltra
    @ChimpanzeeUltra 4 ปีที่แล้ว +2

    What the... I searched for this video in the previous month when I was trying to make a harder project than I make now! Thanks! When I will end with the current project I'll be needing of this video :)

  • @357molotov
    @357molotov 3 ปีที่แล้ว +5

    For anyone who had the same issue as I did; the camera wouldn't stop shaking once it started. So had to change:
    Mathf.Lerp(startingIntensity, 0f, shakeTimer / shakeTimerTotal);
    to this:
    Mathf.Lerp(startingIntensity, 0f, 1 - shakeTimer / shakeTimerTotal);
    Excellent tutorial though, thank you!

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +2

    🌍 Code Monkey on Steam!
    👍 Interactive Tutorials, Complete Games and More!
    ✅ Add to your Wishlist! 👉 store.steampowered.com/app/1294220/

  • @from10sto0z6
    @from10sto0z6 4 ปีที่แล้ว +2

    Thank you so much! Im now on the finishing touches of my first game jam and you have saved my game, Keep rocking the tuts!

  • @ayotundeayoko5861
    @ayotundeayoko5861 2 หลายเดือนก่อน

    thank you so much ! this was VERY helpful...exactly what I needed

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 หลายเดือนก่อน

      I'm glad the video helped you! Thanks!

  • @horrorshelter
    @horrorshelter 4 ปีที่แล้ว +15

    I just realized i don't know anything about unity

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      How so? If you are a complete beginner then don't start with a camera shake effect, start with the absolute basics.

    • @dragovscar
      @dragovscar ปีที่แล้ว +1

      First time?

  • @gamedevjedi8212
    @gamedevjedi8212 4 ปีที่แล้ว +3

    Sweet! I love that effect in certain situations. When, I'm playing haha ...I'm brand new to game development, so probably won't use this for a bit, but still super fun to learn all this new stuff! Thank you buddy!

    • @ScilexGuitar
      @ScilexGuitar 4 ปีที่แล้ว +1

      How is it going, after 5 months ?

  • @BioToxin
    @BioToxin 4 ปีที่แล้ว +1

    Dude I've been wondering about this as a final touch for a while thanks

  • @behnamrasooli8801
    @behnamrasooli8801 4 ปีที่แล้ว +4

    Funny to see that the 'm_AmplitudeGain' field in the 'CinemachineBasicMultiChannelPerlin' class is public! This shows that a team member in Unity doesn't quite understand the naming convention. 'm_' means it's a member variable and it should be private.

  • @s_abhinav
    @s_abhinav 3 ปีที่แล้ว +6

    I love your tutorials but can you please give detailed explanation in coding, as I feel you are little bit faster.🙏🏻
    This is just a suggestion.

  • @skymakr8727
    @skymakr8727 3 ปีที่แล้ว +1

    i have been searched this for ages

  • @VarelaMar
    @VarelaMar 4 ปีที่แล้ว +3

    Wow, amazing! Please make a video about code reusability and how to organize your utils like you do! Thank you, for the great tutorials!

  • @Kn3rd5oftheRoundTable
    @Kn3rd5oftheRoundTable 2 ปีที่แล้ว +1

    Thank you so much great tutorial!

  • @samyam
    @samyam 4 ปีที่แล้ว +2

    Great video, thanks!

  • @jean-michel.houbre
    @jean-michel.houbre 4 ปีที่แล้ว +1

    Hello,
    maybe i'm going to say a big nonsense, but the second method doesn't work. The line with the Lerp is executed only once, the 1st time that shakeTimer is negative.
    Maybe we should put something like:
    if (_shakeTimer

  • @michaelzhao5873
    @michaelzhao5873 4 ปีที่แล้ว +7

    How do you read my mind? My next devlog is gonna require a camera controller rewrite using Cinemachine which I'll use this tutorial for... At this rate, I need to put "Made with Code Monkey's help" in the title screen of my game... 😂

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Hehe awesome! I'm glad the videos have helped you!

  • @ACBros_06
    @ACBros_06 ปีที่แล้ว

    Thank you very much. Very useful video as always

  • @sila2049
    @sila2049 4 ปีที่แล้ว

    Just discovered your channel and I love it!

  • @justusforan
    @justusforan 2 ปีที่แล้ว

    Thank you for this one. Turns out the cinemachine impulse events only fire if there is a box collider, not a mesh or convex collider. This is the missing piece...now to translate this into visual scripting.

  • @TheVicRulz
    @TheVicRulz ปีที่แล้ว

    Nice, that was easy!

  • @suryamdg
    @suryamdg 2 ปีที่แล้ว +1

    Instead of using the singleton pattern I used it diretly in the script I wanted but even though I used getCineMachineComponent on CineMachineVirtual component it is not able to get it on awake and is showing null error

  • @RitleYT
    @RitleYT 3 ปีที่แล้ว

    Thank you so much for this tutorial, it really helped me :) keep up the great work!

  • @ygorishikawa285
    @ygorishikawa285 2 ปีที่แล้ว

    Nice! Excellent video, thanks!

  • @CodingKricket
    @CodingKricket 3 ปีที่แล้ว

    Thanks! This helped so much!

  • @siddhant10thf70
    @siddhant10thf70 3 ปีที่แล้ว +1

    Hey man i saw this video and i followed everything correctly...the only difference is... i am using a freelook camera...idk if that affects it but when i type the command "GetCinemachineComponent" it just doesnt verify it....I even have using Cinemachine on top.I dont know why this is happening.Please tell a solution to this.

  • @yeeeetsssusdelets
    @yeeeetsssusdelets 7 หลายเดือนก่อน

    what if you want to have multiple shakes? so lets say a small shake when an enemy is hit and a big shake for e.g. an "earthquake"? if the big shake is long, then the small shake would just override the big shake

  • @kendrickjba
    @kendrickjba 4 ปีที่แล้ว +1

    hey for some reason my editor can find the CinemachineShake part of public static CinemachineShake Instance{ get; private set;}

  • @rafikbenamara1
    @rafikbenamara1 3 ปีที่แล้ว

    If all your video was like this 😍 thank you very simple and clean

  • @chntnshrff
    @chntnshrff ปีที่แล้ว

    Wonderful tutorial. Thanks. Is it possible to make this shake in only Y axis?

  • @onuroguz940
    @onuroguz940 3 ปีที่แล้ว

    im the 1000th person liked this video

  • @MrMagicznyMAG
    @MrMagicznyMAG 4 ปีที่แล้ว

    Thanks for this tutorial!

  • @bars9803
    @bars9803 4 ปีที่แล้ว

    Oh gosh that's so nice thank you!

  • @lucas90gs
    @lucas90gs 4 ปีที่แล้ว +4

    Thanks for the video! I have one issue that I can't get rid of. I'm doing a 2D game, but I made my Virtual Camera setup just like yours, besides the fact that my camera is only supposed to shake when my Player collides with another collider. When I start the game, the camera is already shaking. If I collide with something it stops shaking, and after this the camera shake works properlly. I tryed to initialize the game with Intensity and Frequency set to 0, but this messes up the camera big time. The camera starts to rotate, and the whole scene turns into a mess. Any ideias on how to fix this?

    • @lucas90gs
      @lucas90gs 4 ปีที่แล้ว

      I know that ShakeCamera method is not called upon game initialization. Could this mean that the issue is in the hierarchy configuration?

    • @lucas90gs
      @lucas90gs 4 ปีที่แล้ว

      I fixed it for the moment. I Serialized a NoiseSettings variable and assigned 6D Shake to it. Back at the CinemachineShake script, in the Awake method, I set the Noise Profile to null. Then, when I collide with something and call the ShakeCamera method I set the Noise Profile to the 6d Shake using the Serialized NoiseSetting. It fixed the issue I had, but I'm curious to know your ideas, since you know a lot about Cinemachine.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Do you have "Save During Play" ticked? If so and you end the game while it is shaking then it will continue shaking when you restart.

    • @lucas90gs
      @lucas90gs 4 ปีที่แล้ว

      @@CodeMonkeyUnity I did not have it on.

    • @ciceAX7
      @ciceAX7 3 ปีที่แล้ว +2

      Hi had the same issue, and solved it.
      My Setup was a MainCamera and with the cm vcam as a child to it.
      This caused the main camera to rotate.
      After disconnecting them (just moving them in the hierarchy so that the cm vcam was not under the main cam but instead outside) this solved the issue.

  • @JPasi97
    @JPasi97 2 ปีที่แล้ว

    Love the video really helpfull, keep it up

  • @makemypetgamedevprocess6475
    @makemypetgamedevprocess6475 3 ปีที่แล้ว

    Thanks for this awesome video, it improved the game feel of my game nicely🙏

  • @christophmuller1556
    @christophmuller1556 3 ปีที่แล้ว +2

    Thanks for the tutorial, the lerping part for some reason isn't working for me though. And yes, I changed it to = Mathf.Lerp(startingIntensity, 0f, 1-(shakeTimer/shakeTimerTotal)); Why doesn't it work?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Use Debug.Log to see what shakeTimer and shakeTimerTotal are doing
      Essentially that third parameter should start at 1 and go down towards 0

    • @XboxPlayerPL
      @XboxPlayerPL 2 ปีที่แล้ว

      It doesn't work for me either. It just snaps the value to 0.

    • @Mr.SilentOne
      @Mr.SilentOne 2 ปีที่แล้ว

      You most likely forgot to remove part of the if statement.
      It should look like:
      private void Update()
      {
      if (shakeTimer > 0)
      {
      shakeTimer -= Time.deltaTime;
      CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin = cinemachineVirtualCamera.GetCinemachineComponent();
      cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
      }
      }

    • @voodoojediknight
      @voodoojediknight ปีที่แล้ว

      The reason it is snapping to 0 and never gets called again because the if statement at the top of Update is checking for shakeTimer > 0 so the Lerp is done once when shakeTimer 0 doesn't pass and that's the end of the execution for the code.

  • @ZiplawDev
    @ZiplawDev 4 ปีที่แล้ว +1

    Please make a full tutorial on Cinemachine :)

    • @T5mpler
      @T5mpler 4 ปีที่แล้ว

      He has

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      I covered Cinemachine here th-cam.com/video/Ml8ptNeezsU/w-d-xo.html

    • @ZiplawDev
      @ZiplawDev 4 ปีที่แล้ว

      @@CodeMonkeyUnity yeah, but you said it's an introduction, and I see barely any advanced tutorials on anything game related, everything just scratches the surface. I'd like to see like a giant tutorial on every component of CM and the API

  • @user-hz4tc2pf3x
    @user-hz4tc2pf3x 4 ปีที่แล้ว +1

    Pixel perfect with cinemachine?

  • @user-em9su3dd9y
    @user-em9su3dd9y 3 ปีที่แล้ว

    Thanks for this!

  • @AlfredoAVA
    @AlfredoAVA 3 ปีที่แล้ว +3

    Awesome tutorial, thank you so much! :D I decided to throw this functionality into a coroutine, that way Update() doesn't have to constantly check for screen shake, and so it can also be called with an Event via a public function. Would there be any significant disadvantages to doing it this way though?
    IEnumerator CamShake(float intensity, float time) {
    float shakeTime = time;
    while (shakeTime > 0f) {
    shakeTime -= Time.deltaTime;
    vCamPerlin.m_AmplitudeGain = intensity;
    yield return null;
    }
    vCamPerlin.m_AmplitudeGain = 0f;
    }
    Either way, thanks again! Your videos have helped my project immensely :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +1

      Yup that should work just fine

    • @XboxPlayerPL
      @XboxPlayerPL 2 ปีที่แล้ว

      And how to reset values in lerp inside couroutine?

  • @peterparkour2918
    @peterparkour2918 3 ปีที่แล้ว

    This was very helpfull, thank youuu!!

  • @simonbahamonde7370
    @simonbahamonde7370 ปีที่แล้ว

    I have a problem using this shake, on a 2D game worked perfectly but now trying in 3D it looks really wobbly after build (played on the editor looks nice tho)... does anyone have any clue on how to solve the wobbliness

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Look at the Shake type profile that you're using, there are multiple presets, some shake on and rotate on all angles, others only XZ

    • @simonbahamonde7370
      @simonbahamonde7370 ปีที่แล้ว

      @@CodeMonkeyUnity Thank you! I'll give it a look, it was weird since in the build for mobile and web looked fine, but only in windows looks weird after building!

  • @collapseboi7847
    @collapseboi7847 4 ปีที่แล้ว

    Thanks sir for the tutorials

  • @Walter_Hartwell_White356
    @Walter_Hartwell_White356 2 ปีที่แล้ว

    Super Useful! thx

  • @antn908
    @antn908 4 ปีที่แล้ว +1

    If I want to apply this to several virtual cameras, how would I go about doing so?
    I use a Cinemachine Clear Shot because I'm switching between cameras when entering a area, would I just manually put the script on every camera or could I place it in the Clear Shot?
    Thanks for a nice tutorial!

    • @antn908
      @antn908 4 ปีที่แล้ว

      I just found out how to do this and even though it took me a while to figure out, it was a really easy process once I knew what to do.
      I'm thinking about making a tutorial video about it because it's really useful information but it's just not very talked about.

    • @kaynac825
      @kaynac825 4 ปีที่แล้ว

      @@antn908 I would like to know, I was wondering that myself. This method works great but I'm noticing it does not like to transfer over to the next virtual cam. Mind sharing the knowledge? :D

    • @kaynac825
      @kaynac825 4 ปีที่แล้ว

      @@antn908 Well, actually I have two cameras set up. It will go over to the second one and work but when I come back to the first one it won't. Like the Instance does not update. Hmm..

    • @kaynac825
      @kaynac825 4 ปีที่แล้ว

      @@antn908 Yea. Nevermind. That was it lol. Adding it to Update().

    • @antn908
      @antn908 4 ปีที่แล้ว

      @@kaynac825 Sure but I'm bad at explaining through text so I'll go into more detail in a video and show what I did there.
      At first I was looking into if I could use a script on the clear shot to apply the shake function to whatever camera that was currently live, but on some forum post one of the cinemachine devs had said something along the lines of -that's no good, use impulses for shakes-. I hadn't heard about the impulse function before and I couldn't find much about it but turns out Cinemachine Impulse is a really versatile tool that allows you to customize shakes and feedback a bunch of ways. There's a script in Cinemachine called CinemachinImpulseSource that does what the same thing as Code Monkeys script does, call it from your shoot function.
      (Sorry, I got this to work at 3am and I haven't slept well at all so I'm not feeling very good right now. I'll try to put up a video showing what I did soon. Hope this was of some help though.)

  • @RustThisWorld
    @RustThisWorld 3 ปีที่แล้ว +1

    Great tutorial thanks. I'm interested in what you do at 4:49, creating a public instance to be easily referenced in other scripts. Do you have any other videos detailing this?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +2

      It's called the Singleton pattern
      Very useful when you have a single instance of a specific class.
      They have some downsides so use them but dont abuse them!

    • @xudee
      @xudee 2 ปีที่แล้ว

      @@CodeMonkeyUnity Thanks for the tutorial! Can I use this method when I have lots of virtual camras, and I just want the active one to shake?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      @@xudee Sure, only the one you're accessing will change

  • @arfcentral1911
    @arfcentral1911 4 ปีที่แล้ว +1

    Hey everybody, for some reason I seem to run into this error after doing the first part of the tutorial before he used Mathf.Lerp... "NullReferenceException: Object reference not set to an instance of an object CinemachineShake.ShakeCamera (System.Single intensity, System.Single time)". I can't seem to find a solution to this error, does anybody know how to fix this? Thanks : )

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Use Debug.Log(); to figure out what is set to null

    • @sophielin5669
      @sophielin5669 4 ปีที่แล้ว +3

      I had this problem too. I figured out I was using the wrong code. Make sure to put CinemachineBasicMultiChannelPerlin multChanPerlin= virtualcam.GetCinemachineComponent(); and include the virtualcam.GetCinemachineComponent part in both the shake function and update!

    • @kej1n
      @kej1n 4 ปีที่แล้ว +3

      Maybe i'm quiet late but, if you wasn't paying attention (like i did some minutes ago) : you have to put the shakeCamera script on the CinemachineVirtualCamera.. Yeah it's late i should go to sleep yeah...

    • @noobatron9046
      @noobatron9046 3 ปีที่แล้ว +1

      @@kej1n i know i'm late but you sir saved me... I was too dumb to figure it out -_- Thank you! It seems we all have that problem that we forget to add the script to an object

  • @mathew3267
    @mathew3267 3 ปีที่แล้ว

    How would you change the profile? I want to use one of the Handheld profiles when I'm not shooting.

  • @lucafernandez1881
    @lucafernandez1881 2 ปีที่แล้ว

    Hey Code Monkey! Great Tutorial, i was wondering, this works when i have more than one cinmeachine camera? I have to add the shake script to the other ones?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Yes you need to add the script and noise to all your virtual cameras
      If working with multiple cameras you might want to look into the Cinemachine Impulse method instead

  • @paradox7336
    @paradox7336 3 ปีที่แล้ว +1

    Loved the tutorial but I am having an issue because I am not being able to set the cinemachine component to the script
    cinemachineVirtualCamera.GetCinemachineComponent();
    can someone help me?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Why can't you set it? Did you add using Cinemachine?

    • @paradox7336
      @paradox7336 3 ปีที่แล้ว +1

      @@CodeMonkeyUnity I did add using cinemachine. I truly have no idea why that is, my editor just doesn't show the option. Btw thanks for responding :)

  • @BastianHodapp
    @BastianHodapp 4 ปีที่แล้ว

    Very nice, thanks :)

  • @fedechaotix
    @fedechaotix 3 ปีที่แล้ว

    Very helpful. Problem is when i trigger the cam shake... my camera doesn't go back to its original position :S

  • @pittherichkid
    @pittherichkid 2 ปีที่แล้ว

    nice one !

  • @MesaTheAalfa
    @MesaTheAalfa 4 ปีที่แล้ว +1

    YOUR ONE OF THE BEST!!! if by any chance you upload courses on Udemy I'll make sure to be your good student

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Awesome! By finishing your game you're taking a very important step!
      Keep it up and keep learning, best of luck!

    • @MesaTheAalfa
      @MesaTheAalfa 4 ปีที่แล้ว

      @@CodeMonkeyUnity Thank you and I will 🤩🤩✨✨

  • @dencen178
    @dencen178 4 ปีที่แล้ว

    Is this going to work with a cinemachine free look camera too?

  • @wizardjo
    @wizardjo 3 ปีที่แล้ว

    There is any way to do this using the Cinemachine Impulse listener feature ? Thank you guys

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Yup that is the other method, just add a impulse listener on the virtual camera, then on any object add a impulse source and through code generate the impulse

  • @johnnylapinator9649
    @johnnylapinator9649 3 ปีที่แล้ว

    thank you Le Code Monke

  • @durrium
    @durrium 3 ปีที่แล้ว +1

    Nice vid! Sometimes it feels like you are over complicating stuff with your coding though

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +1

      What do you mean by overcomplicating? Any specific example?

    • @durrium
      @durrium 3 ปีที่แล้ว

      @@CodeMonkeyUnity maybe it's just me but wouldn't it be more "easy to understand" making a coroutine with the timer?
      Or is that less performant or something?

    • @durrium
      @durrium 3 ปีที่แล้ว

      And also might just be since you speed up the coding that messes with my head😅

  • @utkugokalp3179
    @utkugokalp3179 4 ปีที่แล้ว

    Very good video and really easy to understand explaining. Great work!

  • @Luciferdelight
    @Luciferdelight 2 ปีที่แล้ว

    Thnx so much =)

  • @yuriaugusto1084
    @yuriaugusto1084 4 ปีที่แล้ว

    Great tutorial as always i wondering if there's any way to shake the virtual camera without getting jittering? i have my onw shake script based on GDC camera shake and i would like to implement thoose concepts in cinemachine but LateUpdate don't override cinemachine position....

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Cinemachine takes control of the camera so if you have another script also moving the camera then both of those will be fighting for control
      Your best bet is probably to disable cinemachine while shaking and reenable it afterwards

  • @juanpabon4254
    @juanpabon4254 3 ปีที่แล้ว

    Thank you thank you thank you and thank you :) ,.. bro, a question. Why when changing cameras, I go from VCam 1 to Cam 2, I disable Vcam 1 because I am on Vcam2. But when I go back to Vcam 1 and enable, it doesn't work anymore, it's like sticking to VCam2. Because I go back to VCam2 and it keeps working but VCam1 no longer after the change. Any idea?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Each virtual camera has a priority setting, the system checks for all enabled virtual cameras and uses the one with the highest priority. If they have the exact same priority then I'm not sure how it's chosen

    • @juanpabon4254
      @juanpabon4254 3 ปีที่แล้ว +1

      @@CodeMonkeyUnity Thanks bro, I made some priority changes and it doesn't work. I think it is an instance issue, I don't know if it has to make the file static. Because I see that camera 2 keeps registering changes, but camera 1 is as if it is not sending the parameters. As if the camera file did not receive it. Do you think it has to see the gameobject that is in memory at that moment? how I clean the memory logged by the static file, you know? Edit: I forgot to say that: My game is type (Celeste) one camera for each room, and the shaking is transmitted by an enemy stone that falls in each of the rooms, that is, there are 2 rooms with 2 enemy stones. But apparently the instance stays in room 2 when I return to room 1.

    • @juanpabon4254
      @juanpabon4254 3 ปีที่แล้ว

      @@CodeMonkeyUnity I forgot to say that: My game is type (Celeste) one camera for each room, and the shaking is transmitted by an enemy stone that falls in each of the rooms, that is, there are 2 rooms with 2 enemy stones. But apparently the instance stays in room 2 when I return to room 1.

  • @connorwilson-long1336
    @connorwilson-long1336 2 ปีที่แล้ว

    I keep getting the error "Use of unassigned local variable 'cinemachineBasicMultiChannelPerlin" as well as some other errors to do with the mutilchannelperlin. Help.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Sounds like you defined the variable but never assigned it to any value. Are you doing GetCinemachineComponent()?
      The code on line 15 and 16 at 3:44 is all in one line.

  • @hugh._
    @hugh._ 4 ปีที่แล้ว

    Thanks!

  • @kushalbaid
    @kushalbaid 4 ปีที่แล้ว

    Hey 1st cool video bring more

  • @draggmaste
    @draggmaste 3 ปีที่แล้ว

    hm... This is not really working for me :/ But I have three cams atm stored in a StateDrivenCamera, is there a way to ad screenshake to all of them simultaniously?
    Edit: well, I made it work, I just did the same thing but for all cameras instead of one, alittle clunky but worked.

  • @albikroalperen
    @albikroalperen 2 ปีที่แล้ว

    The positions of objects may be offseted a bit after a rough shake. Any solutions?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Objects? This only shakes the camera, it doesn't touch any object. And as the shake goes down the camera should reset to it's regular position.

    • @albikroalperen
      @albikroalperen 2 ปีที่แล้ว

      Yes, the camera. I used WaitForSeconds for the time. And the "2" value for frequency. When I use shake effect for a few times, I see that my in-game cursor is not matched with my actual cursor (Without shakes, they should be matched). So its offsetted. I meant that actually.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      ​@@albikroalperen But nothing here moves any object other than the camera, so whatever issue you have is in some other code, not in this cinemachine camera shake. Maybe it's something with how you're positioning that in-game cursor, maybe the camera still has some rotation after shaking.

    • @albikroalperen
      @albikroalperen 2 ปีที่แล้ว

      @@CodeMonkeyUnity Maybe its about the frequency, which value would you advice for minimum problem? As I said I tried 2.

    • @albikroalperen
      @albikroalperen ปีที่แล้ว

      @@CodeMonkeyUnity Hey, I found the solution! I saw that every time it shakes, it changes the rotation of my camera. So I wrote a code that changes rotation values to 0 in update. Problem solved!

  • @seppukun208
    @seppukun208 4 ปีที่แล้ว

    Hmmmm.... I wonder how slow the CinemachineVirtualCamera.GetCinemachineComponent() function is. Probably negligible but I still cache mine. Thanks for the tips

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Yup you should definitely cache that value when using this system in a proper game.

  • @shrit-th7go
    @shrit-th7go 3 ปีที่แล้ว

    Heyy man love your videos , but can you put your visual studio to dark theme don't know about you but my eyes will blast open

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      Sorry but my eyes burn with dark mode

    • @shrit-th7go
      @shrit-th7go 3 ปีที่แล้ว

      @@CodeMonkeyUnity Well then you should visit your doctor (no offense, don't want to be rude I am)

  • @feliscape
    @feliscape 3 ปีที่แล้ว

    public static CinemachineShake Instance { get; private set; }
    That doesnt work for me. It doesnt except CinemachineShake because: "the type or namespace 'CinemachineShake' could not be found'

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +1

      Did you name the class exactly CinemachineShake?

    • @feliscape
      @feliscape 3 ปีที่แล้ว

      @@CodeMonkeyUnity I didnt. I just called the instance CamShake (like the class) now. Thanks!

  • @MrSmoofist
    @MrSmoofist 4 ปีที่แล้ว

    For some reason it insist i did not reference the code, cant find the reason why

  • @theonly647
    @theonly647 4 ปีที่แล้ว +1

    Is it 3D project?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Works both in 2D and 3D

    • @theonly647
      @theonly647 4 ปีที่แล้ว

      @@CodeMonkeyUnity Thanks, but what about old videos?

  • @diegoantunes3419
    @diegoantunes3419 4 ปีที่แล้ว

    Hey man, can you make a video showing best way to create Cinematics in Unity and how to put it in-game at decisive points like empty coliders or other technics?

  • @Abazel
    @Abazel 2 ปีที่แล้ว

    Hi, I tried my best to follow this but I keep getting an error saying "NullReferenceException: Object reference not set to an instance of an object" at this line "CameraShake.Instance.Shake(5f, 0.1f);" and the camera then doesn't shake

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Always add some Debug.Log to verify what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
      In that case it can only be the Instance field, maybe you don't have the CameraShake component attached to any object? Maybe you're calling that on Awake before the CameraShake Awake runs?

    • @Abazel
      @Abazel 2 ปีที่แล้ว

      @@CodeMonkeyUnity I think I may have found the problem, I forgot to add “instance = this”

  • @MegaGuanxi
    @MegaGuanxi 2 ปีที่แล้ว

    How to deal with multiple cameras and transitioning between them? For some reason when I have Cam 1 working, and I transition to a new room with another camera, the script stops working.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      If you have multiple cameras you need to access the script directly instead of through the static instance, that field will only reference the last script

    • @MegaGuanxi
      @MegaGuanxi 2 ปีที่แล้ว

      @@CodeMonkeyUnity I'm sorry I'm still super new to coding. How would I access the script directly?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      @@MegaGuanxi Maybe make a SerializeField private and drag the reference unitycodemonkey.com/video.php?v=pD27YuJG3L8

  • @shivamprajapati6839
    @shivamprajapati6839 4 ปีที่แล้ว

    Nice video

  • @MeatLabGames
    @MeatLabGames 2 ปีที่แล้ว

    Hi Code Monkey - I've been following your 3rd person controller videos (they're brilliant).
    Just wanted your thoughts on what was the best way to implement a CineMachine camera shake when using the 3rd person controller - with regards to the aiming.
    Firstly have you covered this in any other video? If so just po
    In those tutorials you are using a second camera to blend between Player Follow and Player Aim. The problem comes because the virtual camera responsible for player aim is always targeting the position in front (the debug ball). I believe its recentering the camera and wildly affecting the shake effect.
    Any thoughts? Perhaps a 3rd Camera needs to be introduced for Solely camera shake?
    Cheers, James 🥰

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Hmm interesting, perhaps the issue is because that camera is set with 0 smoothing, so even if you shake it will instantly go back to the correct position. Maybe one solution would be to dynamically add smoothing while the shake is active?
      Or use a shake profile that moves the camera instead of rotates it

  • @peanutbutteraddict22
    @peanutbutteraddict22 4 ปีที่แล้ว

    ty very much

  • @jordanthebestlass8483
    @jordanthebestlass8483 2 ปีที่แล้ว

    can't find the "CinemachineShake" when using cinemachine. maybe this tutorial needs an update? i'm using unity 2020

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Not sure what you mean, that script was created at 2:30 in the video, it's not a built-in thing

    • @jordanthebestlass8483
      @jordanthebestlass8483 2 ปีที่แล้ว

      @@CodeMonkeyUnity i was following your tutorial, and when i tried typiing in "CinemachineShake," it wasn't in the dropdown that appears. sorry for the misunderstanding.

  • @T5mpler
    @T5mpler 4 ปีที่แล้ว

    Hey this is a very nice tutorial! Can you also tell how to do it smoothly with the normal Camera component? Ik there's one called EZCameraShake but I want to know how to do it smoothly and manually eithout tools

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      The manual way is simply just modifying the camera.transform.position with a basic Random.Range(); or more complex with some Perlin noise

    • @T5mpler
      @T5mpler 4 ปีที่แล้ว

      @@CodeMonkeyUnity alright thank you

    • @T5mpler
      @T5mpler 4 ปีที่แล้ว

      @@CodeMonkeyUnity Hey btw I think it would be cool if you covered Unity Timeline in a video

  • @moon..9852
    @moon..9852 2 ปีที่แล้ว

    can i used this code with cinemachinefreelook????

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Sure, you can shake any cinemachine camera type

  • @TheJungaBoon
    @TheJungaBoon 4 ปีที่แล้ว

    Hi, thanks for the tutorial! I was able to get it working up until the actual shaking part. I can trigger the shake via script, but for some reason, the camera will not return back to its default position after the shake is done. Any ideas as to why that is?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Is the camera set up to follow a point? I'm not sure the shake resets correctly if the camera does not have a move and aim target

    • @TheJungaBoon
      @TheJungaBoon 3 ปีที่แล้ว

      @@CodeMonkeyUnity Hi, thanks for the reply. I managed to get the shake working. One thing I was wondering though: Is there a way to pause the shake if I set Timescale to 0 using a pause menu? At the moment, whenever I pause the game, the camera just keeps rotating in one direction, then snaps back to where it should be as soon as I unpause it.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      @@TheJungaBoon If Cinemachine is using Time.unscaledDeltaTime then changing timeScale wont affect it.
      One way you can do it is maybe make a simple script that tests timeScale and when it's 0 disable the cinemachine component and when its not 0 re-enable it.

    • @TheJungaBoon
      @TheJungaBoon 3 ปีที่แล้ว

      @@CodeMonkeyUnity Thanks a bunch! That fixed my problem!

    • @Nounsi_Dev
      @Nounsi_Dev ปีที่แล้ว

      Hello dude, idk if you would repy to this but my rotation is off after the shaking. how did you fixed it, i try a lot of different way but still no result

  • @truongvantam4994
    @truongvantam4994 8 หลายเดือนก่อน

    Can I have the property like in your video? please!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 หลายเดือนก่อน

      Property? What property? I'm using Cinemachine

    • @truongvantam4994
      @truongvantam4994 8 หลายเดือนก่อน

      @@CodeMonkeyUnity What I want to talk about is your assets in this video

  • @raphaloco
    @raphaloco 4 ปีที่แล้ว

    Can you teach how to make a simple android game like "Florence" in the playstore, i have music studio and artists but i still learning to work with unity, can you help?

  • @statusgrabber8398
    @statusgrabber8398 ปีที่แล้ว

    Sir, I am getting "Null reference exception" error in the line where we get CinemachineBasicMultiChannelPerlin component.
    Please help sir!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Did you attach that extension to the cinemachine? Maybe you added a different type of noise, each type has a different class name

    • @statusgrabber8398
      @statusgrabber8398 ปีที่แล้ว

      @@CodeMonkeyUnity Sir, I have added MultiChannelPerlin type.
      Is there's something else that I am doing wrong?

  • @rauljerilara
    @rauljerilara 2 ปีที่แล้ว

    Why create an Instance for ShakeCamera and not only put in an object and then call the method?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Just so you can easily call the function from anywhere without having to drag references

  • @Thrymbor
    @Thrymbor 2 ปีที่แล้ว

    i got a weird bug. when iu use this effect everytime i shoot, it starts to tilt the world at some point O.o

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      That depends on which shake type/profile you use, some only shake on some axis, some have rotation and others don't

    • @Thrymbor
      @Thrymbor 2 ปีที่แล้ว

      @@CodeMonkeyUnity I used the same like u and the camera is permanent in tilted position. i used the same as u in the video

  • @Videogueimeiro
    @Videogueimeiro 4 ปีที่แล้ว

    Hey there, first of all, thanks for the tutorial! I need help with something though. After the camera shake, the camera stays slightly out of position and with a slight rotation, and i can't find a way to make it return to it's original position, as cinemachine camera takes control of everything. Thanks in advance!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      If you set both parameters to 0 the virtual camera will go to the base position. If that one is still offset then the issue is on your normal parameters

    • @michaelshollaj6428
      @michaelshollaj6428 3 ปีที่แล้ว

      I had that problem too, but I changed this line of script (1-(shakeTimer/ shakeTimerTotal)) I changed it to (0.1f - (shakeTimer/ shakeTimerTotal)) , I think this will solve it

    • @SirKingKrab
      @SirKingKrab 3 ปีที่แล้ว

      @@CodeMonkeyUnity What do you mean by setting both parameters? The noise component or in the script itself? I'm trying to figure out the issue that was mentioned above with the rotation getting offset after the shake ends. I can't set the rotation directly on the cam because cinemachine is doing its own thing with that according to what I've read.

  • @ravipandya198
    @ravipandya198 4 ปีที่แล้ว

    can you also video for normal camera shake

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      I have a ShakeCamera() function in my utilities, it's what I normally use when not working with Cinemachine

  • @bilqinm
    @bilqinm 2 ปีที่แล้ว

    thnx bro

  • @pbthemass9374
    @pbthemass9374 4 ปีที่แล้ว

    Does this work for 3D?

  • @glennenri
    @glennenri 4 ปีที่แล้ว

    You can also do this without the additional script, using animation

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +2

      You can, but then its less adaptable whereas with this you can easily modify the intensity and how long.

    • @glennenri
      @glennenri 4 ปีที่แล้ว

      @@CodeMonkeyUnity yes that's true. It's just that I happen to see some comments about having problems in programming side. Just hoping to somehow help haha. Nice video btw as always. I'm a fan of the channel keep it up

  • @goblinslayer6375
    @goblinslayer6375 3 ปีที่แล้ว

    My Camera is rotating help pls.

  • @diogoantonio7855
    @diogoantonio7855 4 ปีที่แล้ว +1

    Primeiro, vim mais rápido que o Flash