Комментарии:
who have NullReference error >>> write >> private CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin;
ОтветитьNice, that was easy!
Ответитьhelp me ples Object reference not set to an instance of an object
ScreenShakeController.ShakeCamera (System.Single intesity, System.Single time) (at Assets/Scripts/ScreenShakeController.cs:19)
Movement.Update () (at Assets/Scripts/Movement.cs:217)
Whats the best game you maked ? 🎉
ОтветитьWonderful tutorial. Thanks. Is it possible to make this shake in only Y axis?
ОтветитьSir, I am getting "Null reference exception" error in the line where we get CinemachineBasicMultiChannelPerlin component.
Please help sir!
The positions of objects may be offseted a bit after a rough shake. Any solutions?
Ответить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.
ОтветитьThank u so much
Ответитьcan i used this code with cinemachinefreelook????
ОтветитьIf you use FreeLook Camera:
public static CinemachineShake instance;
public float shakeIntensity = 5f;
public float shakeTime = 0.1f;
private CinemachineFreeLook cinemachineFreeLook;
private float shakeTimer;
private void Awake()
{
instance = this;
cinemachineFreeLook = GetComponent<CinemachineFreeLook>();
}
public void ShakeCamera()
{
for(int i = 0; i < 3; i++)
{
CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin = cinemachineFreeLook.GetRig(i).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = shakeIntensity;
shakeTimer = shakeTime;
}
}
private void Update()
{
if (shakeTimer > 0)
{
shakeTimer -= Time.deltaTime;
if (shakeTimer <= 0f)
{
for (int i = 0; i < 3; i++)
{
CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin = cinemachineFreeLook.GetRig(i).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = 0f;
}
}
}
}
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?
ОтветитьWhy create an Instance for ShakeCamera and not only put in an object and then call the method?
Ответить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
ОтветитьLove the video really helpfull, keep it up
Ответить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 🥰
i got a weird bug. when iu use this effect everytime i shoot, it starts to tilt the world at some point O.o
ОтветитьI'm suggesting use coroutine
run like this:
StartCoroutine(nameof(ShakeCamera), new ShakeCameraOptions { DurationInSeconds = 3, AmplitudeGain = 1, FrequencyGain = 1 });
and implement lie this:
private CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin;
private IEnumerator ShakeCamera(ShakeCameraOptions options)
{
//var rigIndex = CinemachineFreeLook.RigNames.Where()
cinemachineBasicMultiChannelPerlin = cinemachineBasicMultiChannelPerlin ?? Cinemachine.GetRig(2).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = options.AmplitudeGain;
cinemachineBasicMultiChannelPerlin.m_FrequencyGain = options.FrequencyGain;
yield return new WaitForSeconds(options.DurationInSeconds);
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = 0;
cinemachineBasicMultiChannelPerlin.m_FrequencyGain = 0;
}
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
Ответитьthanks for the great tutorial!
Ответить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.
ОтветитьI keep getting the error "Use of unassigned local variable 'cinemachineBasicMultiChannelPerlin" as well as some other errors to do with the mutilchannelperlin. Help.
ОтветитьNice! Excellent video, thanks!
Ответитьcan't find the "CinemachineShake" when using cinemachine. maybe this tutorial needs an update? i'm using unity 2020
ОтветитьThank you so much great tutorial!
Ответитьnice one !
ОтветитьCode for those who need it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CinemachineShake : MonoBehaviour
{
private CinemachineVirtualCamera cinemachineVirtualCamera;
private float shakeTimer;
private void Awake()
{
cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
}
public void ShakeCamera(float intensity, float time)
{
CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin = cinemachineVirtualCamera.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = intensity;
shakeTimer = time;
}
private void Update()
{
if (shakeTimer > 0)
{
shakeTimer -= Time.deltaTime;
if (shakeTimer <= 0f)
{
CinemachineBasicMultiChannelPerlin cinemachineBasicMultiChannelPerlin = cinemachineVirtualCamera.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
cinemachineBasicMultiChannelPerlin.m_AmplitudeGain = 0f;
}
}
}
}
Thnx so much =)
Ответитьwhy does my character sprite keep on flickering when I add camera shake?
ОтветитьSuper Useful! thx
ОтветитьGreat post helped me alot. Thankyou.
ОтветитьThank you!
Ответитьthnx bro
Ответить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!
How would you change the profile? I want to use one of the Handheld profiles when I'm not shooting.
ОтветитьThanks! This helped so much!
ОтветитьBruh..
Your typing speed is like a train! WTF
If all your video was like this 😍 thank you very simple and clean
Ответить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?
ОтветитьThere is any way to do this using the Cinemachine Impulse listener feature ? Thank you guys
Ответить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.
Thank you so much for this tutorial, it really helped me :) keep up the great work!
ОтветитьVery helpful. Problem is when i trigger the cam shake... my camera doesn't go back to its original position :S
Ответить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?
ОтветитьMUITO OBRIGADOOOOOO!!!!!!!!!!!!!
ОтветитьNice vid! Sometimes it feels like you are over complicating stuff with your coding though
Ответить