Simple implementation of the effect of shaking screen (shaking camera) in unity3d

Source: Internet
Author: User

Here is a simple camera jitter method, which is recorded for easy reference.

Public class camerashake: monobehaviour {// transform of the jitter target (if no reference is added, how can it be transform of the current object by default) Public transform camtransform; // duration of continuous jitter public float shake = 0f; // jitter amplitude (amplitude)
// The larger the amplitude, the worse the jitter. Public float shakeamount = 0.7f; public float decreasefactor = 1.0f; vector3 originalpos; void awake () {If (camtransform = NULL) {camtransform = getcomponent (typeof (Transform) as transform ;}} void onenable () {originalpos = camtransform. localposition;} void Update () {If (shake> 0) {camtransform. localposition = originalpos + random. insideunitsphere * shakeamount; shake-= time. deltatime * decreasefactor;} else {shake = 0f; camtransform. localposition = originalpos ;}}}

It can actually shake any object.

Simple implementation of the effect of shaking screen (shaking camera) in unity3d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.