Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize camera Jitter with Unity-Cinemachine

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to achieve camera jitter with Unity-Cinemachine. The content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Ordinary camera dithering script is easy to implement, but when using cinemachine cameras, its Transform component cannot be modified by code, so how to achieve Cinemachine camera dithering? The editor systematically explains the three steps to realize camera jitter:

Setup proc

Project background: a 2D pixel action game, we control the Player (must have Collider components), the game camera is Cinemachine 2DCamera (the configuration method is not discussed here, the recommended article is at the reference at the end)

1. Add a monitoring script to the camera

Add components to the virtual camera CM vcam1 we use: AddComponent- > CinemachineImpulse Listener

CinemachineImpulse Listener: listen for the vibration signal in the script (method call) so that jitter occurs on this camera

Channel Mask: Channel mask, which is best defaulted to EveryThing

Gain: the number of vibration signals can be obtained. 0 means shielding, 1 indicates that only one jitter motion can be carried out in a certain period of time.

Use 2D Distance: for 2D games, ignoring camera Z axis jitter

two。 Add a script to the object where the vibration signal occurs

The object that generates the vibration signal (the object that calls the vibration function) is Player, so you need to add a component to Player: AddComponent- > Cinemachine Collision Impulse Source (note: it must be attached to an object with Collider), and then add a vibration configurator in the right gear of Raw Signal-> New Noise Settings. The default name is CM vcam1 Raw Signal.

Cinemachine Collision Impulse Source: a key script with jitter function and vibration configurator

Raw Signal: vibration Configurator, the key components for configuring vibration parameters. When we open the new CM vcam1 Raw Signal just above, we can see all kinds of parameters of vibration mode. We take Position Y, that is, up and down jitter, as an example. After adding Components, we can set its Frequency frequency and Amplitude amplitude, and check the box on the right to set it as a sine wave.

Attack: the change curve and time of the start of jitter

Sustain Time: duration of jitter

Decay: the variation curve and time of jitter decline

3. Call the vibration method:

Reference the vibration core script within the Player and call the vibration method in the appropriate location

Private Cinemachine.CinemachineCollisionImpulseSource MyInpulse

Private void Start () {MyInpulse = GetComponent ();}

Private void Update () {/ / right-click to generate camera jitter, dithering mode according to the above CM vcam1 Raw Signal configuration information if (Input.GetMouseButtonDown (1)) MyInpulse.GenerateImpulse ();}

At this point, we manipulate Player in the game and press the right button to achieve camera jitter. Of course, in addition to the above unparameterized GenerateImpulse () method, there are two methods with parameters:

/ / if the method of transferring velocity is used, the vibration mode is a mixture of velocity and CM vcam1 Raw Signal public void GenerateImpulse (Vector3 velocity); public void GenerateImpulse (Vector3 position, Vector3 velocity)

In addition, there is the possibility of bug: the vibration function has not yet been called, and jitter occurs automatically at the start of the game. The blogger has not found the cause in the corresponding script, but the solution is to close the Cinemachine Collision Impulse Source script on Player.

General description

The basic flow of realizing camera jitter in Cinemachine:

Add a monitoring script CinemachineImpulse Listener to the virtual camera

Add the vibration core script Cinemachine Collision Impulse Source on Player, and add and set the vibration configurator

The Player script calls the vibration function at the right place

This example only introduces the jitter in the direction of a single Position. Readers can configure jitter Position, Rotation, occurrence time, maintenance time, recession time, etc., as needed to achieve the desired effect.

The above is how to achieve camera jitter in Unity-Cinemachine. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report