• 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 /
This question was closed Aug 20, 2020 at 01:40 PM by Noxury for the following reason:

Question is off-topic or not relevant, see Quaternion convert local to world rotation

avatar image
Question by Noxury · Feb 09, 2019 at 11:11 PM · quaternionangleslopesmoothfollowxaxis

Camera direction depending on targets slope (X axis)

I am using the Standard Assets Smoothfollow script. There is a problem: If my target is on a slope, the camera adds no extra yz-position to the corresponding slope angle. The result is that the cam is lowered in aspect to the slope. See Fig. 2. There can not be seen anything whats infront of the target.

alt text

This is the code:

 public Transform target;
 public float distance = 5f;
 public float height = 1.3f;
 public float heightDamping = 1.5f;
 public float rotationDamping = 2f;
 private void LateUpdate() { //TODO: Normal of ground to lift cam extra when elevation
     //Angle calculation
     RaycastHit hit;
     Physics.Raycast (target.position, -target.up, out hit);
     float angle = Vector3.Angle(Vector3.up, hit.normal);
 
     // Calculate the current rotation angles
     Quaternion wantedRotation = target.rotation;
     Quaternion currentRotation = transform.rotation;
     float wantedHeight = target.position.y + height;
     float currentHeight = transform.position.y;
     // Damp the rotation around the y-axis
     currentRotation = Quaternion.Lerp(currentRotation, wantedRotation, rotationDamping * Time.deltaTime);
     // Damp the height
     currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
     // Set the height of the camera
     transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
 
     transform.LookAt (target);
 }


The above code includes the calculation for the angle of the ground. This should be added to the Quaternions x to lift the cam on the "rotation sphere". But this does not work.

smoothfollowxrot.png (81.1 kB)
Comment

People who like this

0 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 Crumpet · Feb 10, 2019 at 04:11 AM 0
Share

any chance I could get the rest of the code with maybe some rough starting values. I'll try to help. its just I don't know what currentSettings.distance is etc.

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

101 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

Related Questions

Relative rotation offset? 2 Answers

Rotation according to gravity 1 Answer

Bone Rotation on X (or any) axis Issues 1 Answer

Mouse Orbit to SmoothFollow and back (Euler to Quaternion possible?) 2 Answers

Head and body rotate threshold 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