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 Noxury · Oct 04, 2017 at 09:48 PM · camera followrotatingsmoothfollowaxesall

How to make Smoothfollow align with targets local Z rotation?

So I want the camera to smoothly stay behind an aircraft, meaning it will lerp to its target rotation and position (with distance/height offset) over time. I know it has been asked like a thousand times, but I always get a camera movement jitter when the physics based jet moves and rotates. This is the camera-script:

 public Transform target;
 public float distance = 6f;
 public float height = 1.5f;
 [Range(0f, 1f)]
 public float lerpSpeed = 0.7f;

 void LateUpdate(){
  transform.position = Vector3.Lerp(transform.position, target.position + (target.forward * -distance) + (target.up * height), Time.deltaTime * lerpSpeed * 60f);
 
 transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, Time.deltaTime * lerpSpeed * 60f);
 }

The standard SmoothFollow is not causing any jitter, however it follows the target at global XZ-plane, meaning it does not rotate when target rotates around its local z-axis (transform.LookAt aswell).

How can this be achieved?

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 MalachiteBR · Oct 04, 2017 at 10:10 PM

Why dont you use transform.lookat instead of rotation ?

I think that even if you dont lerp it, it will look ok because your jet is traveling at high speed so its movements will not be sooo fast...

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 Noxury · Oct 04, 2017 at 10:16 PM 0
Share

Tried that before and didnt worked, but the problem is the cameras position that jitters, and LookAt will rotate the cam on local xy, not local xyz.

avatar image MalachiteBR Noxury · Oct 05, 2017 at 01:05 PM 0
Share

why dont you parent the camera on the jet ?

avatar image Noxury MalachiteBR · Oct 05, 2017 at 01:23 PM 0
Share

I want to smoothly follow the jet.

avatar image MalachiteBR Noxury · Oct 05, 2017 at 04:52 PM 0
Share

try this:

 void Update(){
      Vector3 dir = target - transform.position;
      dir.y = 0; // keep the direction strictly horizontal
      Quaternion rot = Quaternion.LookRotation(dir);
      // slerp to the desired rotation over time
      transform.rotation = Quaternion.Slerp(transform.rotation, rot, speed * Time.deltaTime);
  }

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

70 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

Related Questions

Camera smooth follow behaviour 0 Answers

Smooth camera script looking at left hand side of character. 0 Answers

How to Smooth Camera Follow script for Android? 0 Answers

Switch camera positions from input 1 Answer

Problem in rotating camera around a moving player 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