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 zero_rogue · Aug 01, 2013 at 07:16 PM · spritebillboardlocal axis

billboard sprite along axis

I'm making a sprite that's function is to point towards a location. This it does very well with being parented to an object that sits at that location.

My problem is that this sprite needs to be always facing the camera too.

To put it simply how can I get the sprite to look at the camera while having one axis always pointed at a location?

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
0
Best Answer

Answer by robertbu · Aug 01, 2013 at 08:05 PM

Giving a solution to this kind of problem can be difficult because everyone sets up their objects and environment differently. So I'm going to give you one solution, you can play with. If it does not match your environment, you can tell me how/why and I can help you modify it.

  • Get the CreatePlane script from the Wiki. This script allows the creation of a vertical plane.

  • Create a vertical plane (for your sprite).

  • Get the Math3d script from the Wiki. Specifically you want to use the ProjectPointOnPlane() function.

  • Attach a material with a texture where the pointer is pointing up. I've included one below where the tip of the point ends at the center of the texture (at the default pivot for a plane). There are other ways of solving the pivot point issue.

  • Attach the script to the plane.

  • Drag the object to follow onto the 'target' in this script in the Inspector.


    public class PointAt : MonoBehaviour { public Transform target;

           void Update() {
                 Vector3 normal = Camera.main.transform.position - transform.position;
                 Vector3 totarget = Math3d.ProjectPointOnPlane(normal, transform.position, target.position);
                 transform.rotation = Quaternion.LookRotation (-normal, totarget - transform.position);
         
             }
         }
    
    
    

The concept is that you create two vectors, one between the camera and the pointer. One between the pointer and the position of the target projected onto the plane the sprite will be sitting on. Then LookRotation() takes care of the rotation.

alt text


arrow2.png (3.9 kB)
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 zero_rogue · Aug 01, 2013 at 09:03 PM 0
Share

I guess I made that question too simple. ^_^ I already had everything setup I just needed the code/formula for getting it working.

plugged in the script, and must say wasn't what I was looking for, but I like it a lot more than what I was trying to do. Thanks for the help!

Also excellent tutorial for the next person who has this problem!

avatar image
0

Answer by LittleDreamerGames · Feb 11, 2021 at 03:51 AM

This is a very old post, but I was looking for a more optimized version of the axis aligned billboard script I came up with, and came across this. It looks like everyone is doing pretty much the same way.

Anyway, because I love puzzles, I wanted to figure this one out and share the result. I think you're looking for something like this:

 public class PointerBillboard : MonoBehaviour
 {
     public Transform target;
 
     void LateUpdate()
     {
         if(Camera.main)
         {
             Vector3 up = (target.position - transform.position).normalized;
             transform.LookAt(Camera.main.transform.position, up);
         }
     }
 }

I used the arrow shared by robertbu applied to the Unity Quad shape for my tests. It only works with perspective cameras and you have to use a shader that draws back faces (or make your own quad that faces down -z). It also will only work with a camera tagged with "MainCamera".

Here's what it looks like:

alt text

Cheers!


pointerbillboard.png (8.4 kB)
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

15 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

Related Questions

Trying to make the player/npcs be a billboard of a sprite but can't find a way for it to cast and receive shadows 0 Answers

Billboarded sprite with rigidbody in 3D world - slides around on top of surfaces 1 Answer

Billboarding Sprite issue. 1 Answer

Correct for 2.5D sprite clipping with shader depth offset? 1 Answer

My shader doesn't work if I use the same material for multiple objects with the same texture. 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