Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RogueFactor93 · May 09, 2018 at 02:04 PM · unity 5monodevelopvisual studio

Billboarding in Unity 5 with Locked Z-Axis

I've been trying to get some billboarding done in a scene I've been working on.
.
I'm a level designer, my programming is mostly Python/Scripts for more utilitarian things, I feel completely lost in the world of C#/Java coordinates it seems.
.
Anyways, I was looking for some example code to meander through and poke at for some objective learning and I came across Neil Carter's code for billboarding, it works quite well with planes/quads. Awesome, so I was intending to lock the z-axis to prevent any graphical errors.
.
I was able to follow the code to the bottom without too much trouble, but in order to lock the z axis I would need to replace some code, problem is I have absolutely no idea what to replace at the bottom. I can't seem to wrap my head around the concept of Vector3, I figured it'd call (x,y,z) coordinates, but I'm really confused because in some references of code it seems like people call just 1 number/variable and leave the other 2 blank, but if I do that I get compiler errors.
.
If anyone could give me a hand I would greatly appreciate it. I'm always up for learning new things so if you'd like to explain the code in sections like I'm a 5 year old child I'm cool with that. I'm not the main programmer of the group, but he's on vacation and I kinda wanted to surprise him and learn some C# since it would take some load off of him as well. Plus, we were discussing billboarding vs lowpoly 3D.
.
// CameraFacing.cs // original by Neil Carter (NCarter) // modified by Hayden Scott-Baron (Dock) - http://starfruitgames.com // allows specified orientation axis

 using UnityEngine;
 using System.Collections;
  
 public class CameraFacing : MonoBehaviour
 {
     Camera referenceCamera;
  
     public enum Axis {up, down, left, right, forward, back};
     public bool reverseFace = false; 
     public Axis axis = Axis.up; 
  
     // return a direction based upon chosen axis
     public Vector3 GetAxis (Axis refAxis)
     {
         switch (refAxis)
         {
             case Axis.down:
                 return Vector3.down; 
             case Axis.forward:
                 return Vector3.forward; 
             case Axis.back:
                 return Vector3.back; 
             case Axis.left:
                 return Vector3.left; 
             case Axis.right:
                 return Vector3.right; 
         }
  
         // default is Vector3.up
         return Vector3.up;         
     }
  
     void  Awake ()
     {
         // if no camera referenced, grab the main camera
         if (!referenceCamera)
             referenceCamera = Camera.main; 
     }
  
     void  Update ()
     {
         // rotates the object relative to the camera
         Vector3 targetPos = transform.position + referenceCamera.transform.rotation * (reverseFace ? Vector3.forward : Vector3.back) ;
         Vector3 targetOrientation = referenceCamera.transform.rotation * GetAxis(axis);
         transform.LookAt (targetPos, targetOrientation);
     }
 }

I had another 2 related questions as well.
.
Would it really be better for me/us to build a shader that did the same thing as to help with performance with 1000+ planes/quads? (More extreme scenario) .
After looking around this seems to be something that's requested fairly often, I would've thought that Unity would've introduced a simple billboarding mechanic (Unless I've missed that one, if I did, my bad.) that others could plug into for some prototyping, has anyone done this in the asset store or attempted to?

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

0 Replies

· Add your reply
  • Sort: 

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

167 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityEngine.UI.dll 0 Answers

visual studio tools for unity not working 1 Answer

How to use a boolean to control another object boolean using C# script 4 Answers

Could not connect to debugger 0 Answers

code in void not executing 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