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 superventure · Oct 26, 2014 at 08:09 AM · camerarotationanglerelativeeuler

Video provided-Rotate 2d character in 3d world

video link https://www.youtube.com/watch?v=KMfmu943-m0&feature=youtu.be

Hello. I am trying to rotate a 2d plane relative to the camera depending on the cam's position & rotation to it.

the 2d plan is a character in a 3d world. Of course when the cam comes to or is at the left/right of the plane, the plan will seem to disappear. I am trying to get the character plane to rotate at least 30 degrees at that point towards the left/right depending on the cam position, so it will never 'disappear'.

the closest i came to this was in this attempt

     var checks : float[];
     var myRots : float[];
 
  if(Mathf.Clamp(cam.transform.eulerAngles.y, checks[i]-5, checks[i] + 25) == cam.transform.eulerAngles.y)
      transform.localEulerAngles.y = transform.parent.transform.rotation.y * myRots[i];


Here i manually input camera rotations into the checks string, and when the cam rotation is that rotation, i tell the character to rotate itself accordingly.

this only works until the character itself rotates, then the everything i set becomes incorrect. The character is in an empty gameObject. I rotate the parent obj when moving in the world, and rotate the actual plan as needed for the camera.

Please give an example when explaining- I am horrible at rotations! Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Oct 26, 2014 at 04:02 PM

While I believe I understand your problem, without more of your code and an understanding of the app, I'm unsure of the best fix. Here is my suggestion. I'm assuming you are using Unity's Plane when you write 'plane'. Instead, use a Unity Quad. The geometry is simpler, and it 'faces' the camera by default.

Each frame you get the Vector3.Angle() between the camera forward and the Quad forward. If they greater than 90, then the Quad cannot be seen. So for your 30 degrees check, you would use 60 degrees. If the angle is greater than 60 degrees, then apply the same rotation to the Quad you did to the camera. Untested, but something like this would work:

 #pragma strict
 
 var prevCamForward : Vector3;
 var camTrans : Transform;
 var qPrev : Quaternion;
 
 function Start() {
     camTrans = camera.main.transform;
     prevCamForward = camTrans.forward;
     qPrev = camTrans.rotation;
 }
 
 function LateUpdate() {
     if (prevCamForward != camTrans.forward) {
      if (Vector3.Angle(transform.forward, camTrans.forward) > 60.0) {
         transform.rotation = camTrans.rotation * Quaternion.Inverse(qPrev) * transform.rotation;
         }
     }
     prevCamForward = camTrans.forward;
     qPrev = camTrans.rotation;
 }
Comment
Add comment · Show 4 · 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 superventure · Oct 26, 2014 at 11:07 PM 0
Share

I tried this but it just behaves like transform.lookAt(cam.transform.position). I provided a video to clarify the question.

avatar image superventure · Oct 27, 2014 at 10:44 PM 0
Share

Hello? I seems logical but does not work. Am i missing something?

avatar image robertbu · Oct 28, 2014 at 01:37 AM 0
Share

@superventure - I now understand your problem, but in a quick try I was unable to provide code for an alternate fix. The code above assures that the front side always faces the camera (so you cannot roll around to the back side), but that is not what you want (based on the video). I'll give it another look when I'm back at my desktop and have a bit more time. $$anonymous$$y solution worked for the front side, but not for the back side. The idea was that, when the angle was below some threshold, to rotate the object about an axis create by the Vector3.Cross() of the camera forward and the object forward to flip the object to the opposite side.

avatar image superventure · Oct 29, 2014 at 07:32 PM 0
Share

Awesome! I know there has to be some way to simply it a little more before it faces to camera directly. I just cant put my finger on it

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

27 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

Related Questions

Rotate object in 90 degrees relative to camera. 1 Answer

Position from rotation problem. 1 Answer

Set rotation on y-axis with angle relative to current position 0 Answers

Object makes random jumps in rotation 1 Answer

Instantiate gun & arms rig relative to rotation & position of first person controller camera 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