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
0
Question by rsud · Sep 11, 2012 at 12:54 AM · camerabillboardfacing

Camera facing billboard !

I want a billboard to always face an object (a camera) and I see how to do it documented in several places but none seem to work for me and I can't figure out what is wrong.

Here is my code:

{

public GameObject TargetGO;

void Start() { }

void Update()

{

transform.LookAt(transform.position + TargetGO.transform.rotation Vector3.back, TargetGO.transform.rotation Vector3.up);

}

}

So I drop another GameObject into TargetGO so I can watch the billboard orient.The billboard is always facing 'up' compared to the GameObject.

Tried a simple transform.lookat(TargetGO.transform.position) and this also has the billboard always point up. with billboard at 0,0,0.

What am I doing wrong????

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 Jessy · Sep 11, 2012 at 01:46 PM 0
Share

Please format your code.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FatWednesday · Sep 11, 2012 at 01:00 PM

The following script should do it, it looks like you are over complicating your LookAt perameters. when using the Transform.LookAt function, it automatically takes the transforms position into account, so you only need to provide target vector, not a relative one.

 public class MyClass: MonoBehaviour 
 {
     Transform MyTransform;
     Camera Cam;
     // Use this for initialization
     void Start () 
     {
         MyTransform = transform;
     }
     
     // Update is called once per frame
     void Update () 
     {
         MyTransform .LookAt(Cam.transform.position, upVector);
     }
 }
Comment
Add comment · Show 7 · 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 FatWednesday · Sep 11, 2012 at 01:01 PM 0
Share

and obviously you want to replace upVector with whatever you actually want to be your up vector.

avatar image rsud · Sep 14, 2012 at 04:55 AM 0
Share

This script didn't do it. I think there is something messed up about the initial orientation of my billboard. I have created it and its rotation is 0,0,0.

I used the smoothlookat script (standard assests) and put it in my billboard prefab. The billboard continues to point (face) the upvector of the object (I substitued an gameobject for the camera so I could watch the billboard). As my object flys around in 3d space and changes its up vector so does my billboard to match the upvector of the gameobject.

Have I missed something in setting the prefab up?

avatar image FatWednesday · Sep 14, 2012 at 06:20 AM 0
Share

Depending on the local rotation of your object, you might have to append additional rotation transforms to your object. For example, using the built-in Plane object my rotation has to look like this.

     $$anonymous$$yTransform.rotation = Quaternion.AngleAxis(90, $$anonymous$$yTransform.right) * Quaternion.LookRotation(Camera.main.transform.position, Camera.main.transform.up);
avatar image rsud · Sep 14, 2012 at 05:12 PM 0
Share

Thanks. But do all folks who do camera facing billboard have to do this? I am not doing anything special. I want to create a plane and have it face the camera where it is in 3d space.

So there must be a "easy" way to do this that perhaps I am missing.

I'll try your suggestions. Thanks again!

avatar image Jessy · Sep 14, 2012 at 05:20 PM 0
Share

Shaders are easy.

Show more comments
avatar image
1

Answer by Jessy · Sep 11, 2012 at 01:47 PM

Billboarding is better done in a shader than a script.

http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards http://en.wikibooks.org/wiki/GLSL_Programming/Unity/Billboards http://forum.unity3d.com/threads/109111-GLSL-Animated-sprite-shader-billboard-questions

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

always face camera Billboard not tilt but rotate only 4 Answers

Billboarding flat plane with multiple cameras? 2 Answers

How to get an object's direction relative to the camera? 3 Answers

How can I respawn my RigidBodyFPSController facing new direction? 0 Answers

Move character in direction its facing 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