• 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 SOIL · Jun 23, 2010 at 07:07 AM · cameraflip

Flip/Mirror > Camera?

Is there a way to flip the Camera (let's say in X position), so the whole scene is "mirrored" for example to the right side,?

Comment
Add comment · Show 1
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 buenacolombia · Jan 28, 2019 at 09:00 PM 0
Share

use this scrip

 void Start () {
     $$anonymous$$atrix4x4 mat = Camera.main.projection$$anonymous$$atrix;
     mat *= $$anonymous$$atrix4x4.Scale(new Vector3(-1, 1, 1));
     Camera.main.projection$$anonymous$$atrix = mat;
 }

 // Set it to true so we can watch the flipped Objects

 void OnPreRender()
 {
     GL.invertCulling = true;
 }

 // Set it to false again because we dont want to affect all other cammeras.

 void OnPostRender()
 {
     GL.invertCulling = false;
 }

5 Replies

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

Answer by Mike 3 · Jun 23, 2010 at 11:34 AM

You can use something like this (Once in start should do it):

Matrix4x4 mat = Camera.main.projectionMatrix;
mat *= Matrix4x4.Scale(new Vector3(-1, 1, 1));
Camera.main.projectionMatrix = mat;
Comment
Add comment · Show 6 · 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 SOIL · Jun 23, 2010 at 12:08 PM 0
Share

i haven't tried it yet, need to give that to my programmer, and he is at work atm (got no time). i help him as good as i can and i am only a grafic artist with a bit knowledge about how things work.

  • so we are not talking about a render to texture method?

  • it really flips the whole view in x position?

  • Does it work on iphone too?

avatar image Mike 3 · Jun 23, 2010 at 12:38 PM 0
Share

Should do. Flips the camera horizontally on 2.6, and the same function is there for iphone. It's old style flipping, nothing fancy,should work on any computer

avatar image SOIL · Jun 23, 2010 at 01:43 PM 0
Share

you are my god :D thnx!! is exactly that code the one which works on iphone too? xD

avatar image SOIL · Aug 09, 2010 at 03:16 PM 1
Share

Hello $$anonymous$$ike, we tried the script now. It seems to work, but it flips the normal matrix of all objects. in play mode the camera is facing to the right direction. in game mode i recognize my objects areflipped. but it's like all normals where flipped too. Do you know how to fix that problem?

avatar image Edy · Sep 10, 2010 at 10:37 PM 1
Share

Doesn't work... normals are also flipped so the mirrored camera renders objects something like inside-out, and terrain surfaces are not rendered at all.

Show more comments
avatar image
5

Answer by videordealmeida · Jan 17, 2017 at 03:30 PM

Just use the attached script in your camera, it will flip the image according to the editor selection and fix the culling accordingly.

 using UnityEngine;

 [RequireComponent(typeof(Camera))]
 [ExecuteInEditMode]
 public class MirrorFlipCamera : MonoBehaviour {

     new Camera camera;

     public bool flipHorizontal;

     void Awake () {
         camera = GetComponent<Camera>();
     }

     void OnPreCull() {
         camera.ResetWorldToCameraMatrix();
         camera.ResetProjectionMatrix();
         Vector3 scale = new Vector3(flipHorizontal ? -1 : 1, 1, 1);
         camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(scale);
     }

     void OnPreRender () {
         GL.invertCulling = flipHorizontal;
     }
     
     void OnPostRender () {
         GL.invertCulling = false;
     }
 }
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 zqcolor · Aug 18, 2017 at 07:49 PM 0
Share

This one works in non-vr mode, in google cardboard VR mode, it seems not working, Any suggestions? thanks

avatar image
2

Answer by StephanK · Jun 23, 2010 at 11:04 AM

If you have render to texture (pro only) you could easily achieve this by rendering a texture and then flip that texture before it's displayed.

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 SOIL · Jun 23, 2010 at 12:04 PM 0
Share

That's a solution for Animated Textures or so. What i need is a flip for right handed iphone users. the whole game-view shell be flipped, and the touch-matrix would be moved to the right position too. thing is my game works with on thumb. and the touchfield for it is atm on the left side. if i want to move the touchfield to the right side, i also have to flip the camera in x position, cause the game is strictly layouted on that way.

avatar image
0

Answer by devigod · Mar 11, 2011 at 04:10 AM

There is the answer: http://wiki.unity3d.com/index.php?title=InvertCamera

Comment
Add comment · 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
0

Answer by shacharoz · Feb 05, 2020 at 12:56 PM

any ideas why the vertical flip cant work together with the horizontal one (in conjunction)? it causes render issue.

 Vector3 scale = new Vector3(-1, -1, 1);


Comment
Add comment · 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

how to flip the camera? 1 Answer

Flip a render texture? 2 Answers

Mirror flip camera? 4 Answers

camera rotating with player 2 Answers

Camera Rotation stay behind player and not flip 2 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