Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by ivoisbelongtous · Aug 19, 2014 at 04:19 PM · camerascreenperspectiveshake

Is it possible to shake the screen rather than shake the camera?

Hi, for my action game I've been implementing a method to create a screen shake effect that will be used when bullets are fired by the player.

So far I've successfully written a script that utilises perlin noise to move the camera. My problem, however, is that I am shaking a perspective camera, which means that objects further away shake far less than objects in the foreground when the script is enabled. This results in quite a weird effect and reduces the potency of the screen shake illusion.

Is there a way to actually shake the whole of the view (preferably without moving the GUI) instead of just the camera in Unity, meaning that all objects will shake at the same magnitude regardless of their distance from the camera? My game is effectively in 2.5D with a topdown view, with an additional camera which zooms in to the player, so (I'd think) objects do actually need to be at various y coordinates to achieve proper parallax.

Hopefully I've made myself clear, thanks in advance for helping!

Comment
Add comment · Show 2
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 $$anonymous$$ · Aug 19, 2014 at 04:24 PM 0
Share

$$anonymous$$ake a screenshot -> asign it to a sprite -> add a "shake animation" to the sprite.

avatar image ivoisbelongtous · Aug 19, 2014 at 04:37 PM 1
Share

@$$anonymous$$ Sorry, I should have been clearer that when I say my game's in 2.5D I mean that everything is rendered in 3D, but you play it on a 2D plane (the obvious example of a 2.5D game would be the New Super $$anonymous$$ario Bros. series). Just animating every object with the same shake animation will still yield the same issue as my original question - objects further away will appear to move less than objects in the foreground. And there's no way to tell how far away some objects will be from the camera ahead of time, so I cannot adjust the animation's magnitude accordingly.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by ivoisbelongtous · Aug 20, 2014 at 12:09 PM

Thanks to @Eric5h5 pointing me in the direction of adjusting the camera projection, I have managed to make a very simple function that offsets the camera by the passed amount in the x and y directions -

 void OffsetCameraObliqueness (float xOffset, float yOffset) {
     float frustrumHeight = 2 * camera.nearClipPlane *
         Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
     float frustrumWidth = frustrumHeight * camera.aspect;
     Matrix4x4 mat = camera.projectionMatrix;
     mat[0, 2] = 2 * xOffset / frustrumWidth;
     mat[1, 2] = 2 * yOffset / frustrumHeight;
     camera.projectionMatrix = mat;
 }

This is very useful for shaking the whole screen! I recommend you generate the x and y offsets using perlin noise to achieve a more natural shaking effect.

Please post a comment if you have any questions! And thanks a lot everyone who helped me out. :)

Comment
Add comment · 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 Czar-Man · Mar 30, 2017 at 10:46 PM 0
Share

Sounds great! Could this be used on the StandardAssets ThirdPersonCamera? If so, how?

avatar image
1

Answer by Eric5h5 · Aug 19, 2014 at 05:37 PM

You could move the vanishing point:

http://wiki.unity3d.com/index.php?title=OffsetVanishingPoint

Comment
Add comment · 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 ivoisbelongtous · Aug 19, 2014 at 07:10 PM 0
Share

Thanks a lot! Not sure how useful this will be in a commercial product with the CC BY-SA licensing though... (I'm not an expert in legal matters!)

avatar image
0

Answer by grahnzz · Aug 19, 2014 at 04:36 PM

http://docs.unity3d.com/ScriptReference/Camera-rect.html

by changing Camera.rect x and y you would shake the whole rendered frame - note that u will have borders around the surface, you would probably have the surface a little bigger than the screen and keep your shakings in that range so no borders get visible

Comment
Add comment · 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 ivoisbelongtous · Aug 19, 2014 at 04:49 PM 0
Share

This is great, thanks! Can't believe I haven't seen this mentioned on any other screen shake topics, but maybe I just missed this detail. Giving this a shot now :)

avatar image ivoisbelongtous · Aug 19, 2014 at 05:28 PM 0
Share

Sorry, I'm struggling to find a way to make the Camera's viewport bigger than the screen itself. The normalised width and height seem to clamp at 1? Would it be possible to provide an example to show how to increase the camera's size in order to remove the borders? Or have I misunderstood your solution?

avatar image ivoisbelongtous · Aug 19, 2014 at 05:34 PM 0
Share

Actually no, it doesn't clamp, but centres the camera's view to the screen when possible. For example, shakeyCamera.rect = new Rect (-0.1f,0,1.1f,1f); has no visible effect, even though the camera's x coordinate has been moved 10% to the left. Is there a way around this?

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera Shake 4 Answers

Screen Shake Effect 7 Answers

How can i touch objects in perespective ? 0 Answers

iTween Shake intensity issues 1 Answer

Convert type UnityEngine.Vector3' to float' Error 1 Answer


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