• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by SirBedlam · Jul 23, 2014 at 10:06 PM · cameraeffectshakeconstantcontinuous

Camera Shake Effect (Constant)?

I need a camera shake effect that is continuous and doesn't just shake once, but every single answer to t$$anonymous$$s question out there only offers a one-time shake function. As if that weren't annoying enough, it's always the same exact script. (Why is there always such an infuriating lack of solutions for the most basic and widely used game features when it comes to Unity?) I've tried taking the infamous "if (shake > 0)" script and just getting rid of the line that decreases the "shake" variable every frame, but then as the camera shakes, it gets farther and farther away from where it's supposed to be, until it's completely out of bounds. I need to keep track of where the camera is supposed to be, and KEEP IT THERE, not let it bounce around constantly getting a new reference point in 3D space that's progressively more and more offset from the player. Does anybody know a good way to do t$$anonymous$$s (preferably in JS)?

The script that offsets the camera:

 var shakeTime = false;
 var shakeAmount : float;
 
 function Update() {
      
     if (shakeTime == true)
     { 
         Camera.main.transform.localPosition = Random.insideUnitSphere * shakeAmount;
     }
 }

Comment
AlucardJay
Andres-Fernandez
Ylex

People who like this

-1 Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirBedlam · Jul 24, 2014 at 01:40 AM 0
Share

No answers? Nothing but a thumbs down? Really? Oh, I just love how kind and helpful this community is. The generosity and support here is just exceptional.

avatar image Razacx · Jul 24, 2014 at 02:29 AM 1
Share

Perhaps learn some math and programming and do it yourself?

avatar image SirBedlam · Jul 24, 2014 at 06:45 AM 0
Share

Do it myself? That's such a helpful response! I never even thought of that! I totally didn't just come here as a last resort hoping to get a real answer, that would just be silly.

avatar image CHPedersen · Jul 24, 2014 at 07:54 AM 3
Share

Programming is not easy. It's probably the most sophisticated craft in the world. There's a reason why programmers have an average annual salery of around $80.000 in the US. And that's an average which includes all the script kiddies, HTML 'programmers' and small-time Excel VBA hackers and the like. The really good ones, the hard-core C++ wizards, people with extensive .Net framework knowledge and total C# mastery, those guys earn way, way more.

And here you are, expecting people with skill-sets that valuable to work for you, for free. People respond to you negatively because you make the assumption that people are willing to just start putting their sophisticated craft to use to develop arbitrary things for online strangers with a curmudgeon reaction pattern.

Why would you do that? Do you expect plumbers to come by and fix your sink for free if water starts spraying? Should car mechanics just fix your car for free when it breaks down?

We do not get paid by Unity nor any of the people we reply to, here; we do this in our own free time. This means we're not gonna code new scripts for you, but what we can do, is to make our expertise available to you for advice and directions for code you yourself have started writing, but are unable to finish successfully. But it means you have to do something yourself first. You have to demonstrate your own attempt to solve this problem yourself. You said something about "the infamous if(shake > 0)"-script. I have no idea what script you're talking about and what its code looks like. You didn't post it - you didn't even bother to link to where you got it from. Some dude's whatever-script you found online is not "infamous". Your question is woefully stripped of any concrete presentation of what approach you've taken, and instead laden with frustration and bad attitude. Not a combination that motivates people to come to your aid.

I don't say this to bitch at you, scold you or troll you. I wouldn't have put in the time to write this huge comment if that were the case. I genuinely want you to succeed at this. But these kinds of questions get you nowhere. So, to go forward from here:

Post your own exact attempt, describe at precisely which line of code it fails, or, barring that, where in the code your understanding falters. Then we'll be happy to explain to you what the code does so you have a better chance at tackling similar issues in the future. We can also provide links to online resources and step-by-step tutorials that teach how to program for Unity. But it ultimately takes your concentrated effort to solve it. That's what leads to those high-paying jobs I mentioned. :)

avatar image SirBedlam · Jul 24, 2014 at 07:06 PM 0
Share

I'm sorry, but I can't even make myself read the entirety of that lengthy, smug comment. You're assuming I don't know how to program why? Because I haven't provided any code? The reason for that is because the code I've tried using doesn't even do what I need it to, and I'm not even sure how to go about this. Is it so horrible that I come here empty-handed asking for "a good way to do this" simply because I don't know how to approach it myself? Do I really need to make an offering so I don't get criticized? I suppose I'll edit my post to include the script that causes the camera to gradually move away from the player, because that's really all I have at the moment.

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SirBedlam · Jul 24, 2014 at 10:11 PM

I figured out how to make it work, thanks to Razacx for making a rather obvious suggestion that I'm not sure why I didn't t$$anonymous$$nk of. For anyone who might have a similar problem and happen stumble upon t$$anonymous$$s in the future, basically, I ended up using t$$anonymous$$s code for the shaking:

 Camera.main.transform.localPosition.x = Random.insideUnitSphere.x * shakeAmount;
 Camera.main.transform.localPosition.y = Random.insideUnitSphere.y * shakeAmount + 1.78;

I thought the code I posted was the code that was causing the offsetting of the camera, but I had tried more than one solution to no avail, so I guess I got them mixed up. Either way, the code I posted still had a big side effect - it was resetting my camera's Y position back to the center of the Character Controller object it was parented to, as it was staying wit$$anonymous$$n the limits of shakeAmount. To counter t$$anonymous$$s I simply added a float w$$anonymous$$ch was just under the Y axis of my camera's local position.

I also wasn't even aware that one could specify individual axes with "Random.insideUnitSphere", but I thankfully figured that out and was able to get the shaking just how I want it.

For some reason I had initially thought that resetting the position at all would prevent the shaking from working properly, so it's a good t$$anonymous$$ng I decided to just go ahead and try it anyway. Again, Razacx's simple suggestion is what brought me to t$$anonymous$$s solution, so thanks for that, Razacx.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by smallbit · Jul 24, 2014 at 01:58 AM

The community is fine, they probably wont answer because you behave like a pretentious jerk. Camera script shake is based on modifying transform and rotation by random values, If you want to keep it not going away you either reset the position to origin ( store its transform.position at start to vector 3 variable). and than if it goes too far (check if the position moved to much) or after a time, you just set the transform position back to origin. Alternatively you could do a loop animation of the camera shake but it will be hard to ac$$anonymous$$eve the same effect as a random script.

BTW you have gathered many badges here it means you have been here for a w$$anonymous$$le, why you keep coming back if the community is so bad ?

Comment
AlucardJay
Razacx
SirBedlam

People who like this

1 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirBedlam · Jul 24, 2014 at 06:41 AM 0
Share

"you behave like a pretentious jerk" - yes, such a kind and helpful community indeed. Calling me a pretentious jerk (which doesn't even apply in this case) is the kind of behavior that drives me away from this deepening sinkhole of a community. My post is fine, the community is not. It started out kind and helpful, but it's going down the toilet. I'm certainly not the only one to think this community is rude, either.

avatar image Razacx · Jul 24, 2014 at 10:56 AM 0
Share

You're the first one I have seen on this webpage with such a rude attitude towards the communtity tough.

avatar image SirBedlam · Jul 24, 2014 at 06:47 PM 0
Share

Rude attitude? I was saying absolutely NOTHING rude. Notice in all these situations, the OP starts out saying something that isn't necessarily rude, but just something other people don't agree with. Then once THOSE people comment with the rude attitude and the OP replies in the same nature, everyone in this community always says they're just being rude. I've seen it happen many times here and on the forums, as apparently much of this community is made up cliquey trolls. This is the first time I've personally encountered a situation like this on my own post, and I hate that it's even happened. If my original posts came off as rude, that's not how they were intended to be. I'm not going to try and hide the fact that I was frustrated with the problem I'm having, as that's pretty obvious. BUT, I never attacked anyone, and never even said anything about the community at all until I saw that my question was sinking down the list, with absolutely no responses other than a gratuitous downvote (2 downvotes now). You can't honestly think judgmental, uncalled for behavior like this is what makes a good community. Which, by the way, I've never seen in any other community, just here. A while back, it never would've crossed my mind to respond like this, but the reason I did was because I'm pretty much just getting fed up with a lot of the people here. Certainly not all, but a lot. I want to still like this community, but there's just not as much left to like anymore. I really don't want this to stray any further off topic, I just wanted to clarify some things. Again, my intentions were never to be rude.

avatar image

Answer by Razacx · Jul 24, 2014 at 08:20 PM

I apoligise for my previous comments, but the main reason why I was upset was from the first comment you posted on your own question.

Now back to the question at hand. There is not$$anonymous$$ng inherently wrong with the script you provided, it looks like it works well. I presume that you have parented another object to the camera? If so then after the shaking is done (shaketime == false), you can just put the localPosition of the camera back to Vector3.zero.

T$$anonymous$$s parented object will actually be the reference point of where the camera is supposed to be in t$$anonymous$$s case. As such, when wanting to change the camera's position, change the parented object's position instead.

I'm not sure if t$$anonymous$$s was really the answer that you were looking for tough, so feel free to ask more questions if needed.

Comment
SirBedlam

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SirBedlam · Jul 24, 2014 at 10:16 PM 1
Share

Thank you, this actually helped me come to a solution that I should've already come to on my own. I'm not sure why I didn't. As for the whole 'rudeness' matter, I also apologize for my earlier behavior. I was a little too worked up over this whole issue.

avatar image

Answer by idbrii · Feb 28, 2021 at 07:04 AM

If you put your object under a parent that sets the world position, you can offset the localPosition to give it shake and when your offset goes to zero your object will return to the neutral position. You can keep moving the parent around as needed, but the c$$anonymous$$ld can keep applying the shake.

Please don't use random values to cause camera shake! Use a continuous function like perlin noise or sine to get smooth movement.

Here's a C# script ShakeIn2D that can shake objects or camera as shown in these videos. It has a continous mode that applies nonstop shake.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera shake, everything disappear from screen except canvas. 3 Answers

Camera layering with post processing? 0 Answers

Can you use a camera effect that only applies to a certain layer? 1 Answer

camera effect 2 Answers

How do I cause FPS Camera to shake temporarily from walking into an area? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges