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 Potatobob · Dec 12, 2016 at 02:34 AM · lookatrotation axisrotatetowards

How to use Look-at using only 2 axis to rotate.

Hi, I want to begin by saying that I did search and found for answers about this topic in the past and I also tried multiple times to apply the answers I found.

Sadly I still have issues to constrain the rotation on the z axis :(

We are lucky though as I can show you guys my code and a video of the issue !

(note that the z axis I talk about is pointing down for the character feets , I want to point with my feets but not rotate left and right while doing so) First of here is my code for the look-at:

             float oldZ = transform.rotation.z;
 
             playerAnglePreview.LookAt(gravityTarget.position);
             oldZ -= playerAnglePreview.rotation.z;
             playerAnglePreview.Rotate(0,0,oldZ);
 
             Vector3 desiredRot = playerAnglePreview.rotation.eulerAngles;
             transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(desiredRot) ,Time.deltaTime * weightPower);
 
             // Note I also tried to make a look at using the position.z of this object but it dint work either..
 
 /*            dir = currentGravityText.text;
             Vector3 desiredRot = Vector3.zero;
             if (dir == "up")
             {
                 desiredRot = new Vector3(-90,0,oldZ);
             }
             else if (dir == "down")
             {
                 desiredRot = new Vector3(90,0,oldZ);
             }
             else if (dir == "left")
             {
                 desiredRot = new Vector3(0,-90,oldZ);
             }
             else if (dir == "right")
             {
                 desiredRot = new Vector3(0,90,oldZ);
             }
             else if (dir == "front")
             {
                 desiredRot = new Vector3(0,0,oldZ);
             }
             else if (dir == "back")
             {
                 desiredRot = new Vector3(0,180,oldZ);
             }
             transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(desiredRot) ,Time.deltaTime * weightPower);*/
 
             /*
             down = (90,0,oldZ);
             up = (-90,0,oldZ);
             back = (0,180,oldZ);
             front = (0,0,oldZ);
             left = (0,-90,oldZ);
             right = (0,90,oldZ);
             */
 

The part before the first comment is what gives the result you see in the Video , I am pretty much desperate at this point. I really need to be able to switch the directions the foot of the player look at WITHOUT changing the rotation from left to right,

I can change the gravity and walk on walls just fine as you can see but the camera makes the look at on all the 3 axis :(

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

57 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

Related Questions

lookAt on the x axis, without the 180°turn! 3 Answers

Look at object when entering a trigger 1 Answer

Rotate slowly to target position? 3 Answers

Flying player Rotates in the left and right direction not forward and back 1 Answer

Rotating Game Object in Movement Direction on planet with Faux Gravity Unity 3D 2 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