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 zephren · Feb 02, 2013 at 06:50 AM · camerabillboardfacing

always face camera Billboard not tilt but rotate only

Greetings, I am using a simple script to always have my 2d characters face the camera, however my camera is isometric and in 3d, and my characters tilt on the x-axis when I am walking near them making them appear to be falling over or go into walls etc (all around ugly effect),

is there a way to only make it so the characters will rotate but never tip over or tilt?

here is my script I am using"

camerafacingbillboard.cs

using UnityEngine;

using System.Collections;

public class CameraFacingBillboard : MonoBehaviour { public Camera m_Camera;

 void Update()
 {
     transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.back,
         m_Camera.transform.rotation * Vector3.up);
 }

}

thanks in advance for your help

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 whydoidoit · Feb 02, 2013 at 08:48 AM 0
Share

I wrote an article on rotations that might help with this on Unity Gems

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by falican · Feb 02, 2013 at 08:47 AM

There might be a more elegant way but what about resetting the x axis value after the call to LookAt?

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
1

Answer by robertbu · Feb 02, 2013 at 08:00 AM

Set the 'Y' position of the point to look at to the same 'Y' as your character before calling LookAt (this assumes standard setup with camera looking down Z axis):

For example (untested):

 Vector3 v3T = transform.position + m_Camera.transform.rotation * Vector3.back;
 v3T.y = transform.position.y;
 transform.LookAt(v3T, Vector3.up);
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
1

Answer by whydoidoit · Feb 02, 2013 at 08:54 AM

In a 3D game, LookAt doesn't really work for billboarding well - you actually want to set the Y rotation to make a billboard's forward be the inverse of the camera's forward.

The problem is that the camera is a point in 3d space, but it's view is a plane. Using LookAt will always cause the objects to rotate strangely when you get close to them (because they are looking at the camera and not the plane). The following will fix that on Y only. In Isometric LookAt might just work...

 var cameraForwardForOrient = Quaternion.LookRotation(-CameraMain.transform.forward).eulerAngles;
 cameraForwardForOrient = Quaternion.Euler(0,cameraForwardForOrient.y,0);

         


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 zephren · Feb 03, 2013 at 03:49 AM

Thanks so much for your replies, But I am by no means a coder, so I wouldn't know how to implement your answers into a usable format,

so, How would I do this in my code?

var cameraForwardForOrient = Quaternion.LookRotation(-CameraMain.transform.forward).eulerAngles; cameraForwardForOrient = Quaternion.Euler(0,cameraForwardForOrient.y,0);

sorry for my ignorance, but you know what they say "ignorance is bliss" and I guess I am a very happy person. :)

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

11 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

Related Questions

Camera facing billboard ! 2 Answers

Camera not facing back of character 0 Answers

Billboard Particles Orienting to User in VR 1 Answer

Setting camera to terrain generated billboards 0 Answers

problem with camera and look at in unity network 0 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