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 Arookas · Jul 18, 2013 at 12:21 AM · cameraeventmultiplebillboard

Billboarding flat plane with multiple cameras?

Hello. I understand how to billboard a sprite-plane object to a single camera, but I need to billboard these sprites (in my case, these are characters, a la Doom) to multiple cameras simultaneously (e.g. split screen?).

Since an object can only take up one rotation at a time, I would need access to some "pre-render object/scene" event for each camera, and rotate the player's sprite plane to face the current camera. Trouble is, I need the billboard rotation part be executed player-side, not camera-side (because in my case, I do dynamic scaling and other tasks that are tied into current character state not accessible to a camera).

Is there any event/message that could be of use? Thanks in advance.

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

2 Replies

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

Answer by s-m-k · Apr 10, 2014 at 10:42 PM

I know it might be a little bit too late, but it might be useful for other people as well (including me). I came up to solution that just works on plain Quads (tested) and feels fairly clean.

Actually, the script didn't work with OnPreRender well, so I used OnPreCull.

If we want to keep the code clean, we should limit the amount of information cameras and billboards share between each other. This is the situation when statics and delegates make sense. Here's my solution:

First, attach the following script to each camera:

 using UnityEngine;
 using System.Collections;
 
 public class CameraPreRender : MonoBehaviour {
     public delegate void PreCullEvent();
     public static PreCullEvent onPreCull;
 
     void OnPreCull() {
         if (onPreCull != null) {
             onPreCull();
         }
     }
 }
 

Then attach the following script to each billboard:

 using UnityEngine;
 using System.Collections;
 
 public class Billboard : MonoBehaviour {
     void OnEnable() {
         CameraPreRender.onPreCull += MyPreCull;
     }
 
     void OnDisable() {
         CameraPreRender.onPreCull -= MyPreCull;
     }
 
     void MyPreCull() {
         //we want to look back
         Vector3 difference = Camera.current.transform.position - transform.position;
         transform.LookAt(transform.position - difference, Camera.current.transform.up);
     }
 }

That's it! The code is simple and flexible, you can enable/disable/create/destroy your billboards/cameras on the fly and the code should work (it works for me at least).

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 Arookas · Jul 29, 2014 at 06:33 AM 0
Share

That's ingenius! Thanks for your answer; much appreciated!

avatar image
0

Answer by Benproductions1 · Jul 18, 2013 at 01:40 AM

http://lmgtfy.com?q=Unity+prerender

Was that so hard?

Comment
Add comment · Show 5 · 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 s-m-k · Apr 10, 2014 at 09:52 PM 0
Share

OnPreRender: "This function is called only if the script is attached to the camera and is enabled."

Arookas: "Trouble is, I need the billboard rotation part be executed player-side, not camera-side"

Now it's not that simple, isn't it? He obviously knows OnPreRender, but wants to keep his code as clean as possible and asks for the most clean and simple solution.

Your answer is totally useless.

avatar image Benproductions1 · Apr 11, 2014 at 11:21 PM 0
Share

There is no event that gets called on all objects for every render. $$anonymous$$y answer isn't useless because it's the only answer there is. This is the most clean and simple solution

avatar image s-m-k · Apr 12, 2014 at 03:23 AM 0
Share

It's not a solution, it's not the answer to the problem. Also, you seem to be shortsighted clai$$anonymous$$g that it's the only possible answer to that problem, I'll tell you why later.

He asked how to execute the OnPreRender listener code in the object itself, which is not possible directly.

If we want to achieve it in the clean way, the best I can think of for now is an implementation of Pub/Sub pattern. It supports loosy object coupling, so both camera and billboard don't need to know too much information about each other (both are independent from each other).

This is one of several possible solutions to that problem. You can, for example, just inform your cameras about all billboards and tell them to call appropriate functions by themselves (loop through all billboards and call PreRender or sth). But that's an ugly solution. It needs more work, it makes the camera's code less flexible and dependent on the Billboard class.

Your answer is simply a clue. It's useless, because the author is aware of it, at least his post indicates so. Also, my solution works on OnPreCull, not OnPreRender (I've tested it). OnPreRender "shifts" the billboard's transform to the next camera, also it makes more sense to use OnPreCull here, because our transform can deter$$anonymous$$e the visibility of our billboard.

avatar image Benproductions1 · Apr 14, 2014 at 04:35 AM 0
Share

I see no indication that the OP knew anything about OnPreRender.

I would need access to some "pre-render object/scene" event for each camera

$$anonymous$$akes it quite obvious. None the less, yes, your solution is better, but that doesn't excuse the lack of research from the OP.

Probably the best solution is to do this with shaders.

Also I don't understand why you would revive this question, it was obviously dead a long time ago...

avatar image s-m-k · Apr 14, 2014 at 01:05 PM 1
Share

You're right, the question is dead, but I ran into the same issue, googled it just in case Unity has a native easy-to-use support and thought that the answer would be just useful to others.

I assumed OP knew about OnPreRender event from here:

Trouble is, I need the billboard rotation part be executed player-side, not camera-side

He knew that the event is executed per-camera and asked for "pre-render object/scene" event.

You're right about the shaders, it might be even simpler, because it would probably eli$$anonymous$$ate the need of listening to the events at all. I'll do something about it later.

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

18 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

Related Questions

ratchet and clank style camera 0 Answers

How to use iTween to achieve a camera move with multi - path? 1 Answer

Multiple orthographic cameras issue 2 Answers

Rotation of Camera Slowing Down and Stopping? 1 Answer

Camera focusing on an object specified in a script 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