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 /
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
0
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
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 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: 

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

making a camera that moves depending on mousepos.y 0 Answers

How to get angular difference? 2 Answers

Unity, walking up small steps with rigidbodies 2 Answers

how to get the signed angle between two quaternion? 1 Answer

Rotate angle between two points 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