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 /
  • Help Room /
avatar image
0
Question by DevedGames · Jul 28, 2017 at 10:57 AM · camerascripting problem

Problem with a Camera Follow Script

Hello, so i got a Script that Follows my Spaceship around, Everything works fine, but if i rotate around the z axis my camera also rotates z and x, but why x, maybe you guys can help me with that.

thank you Maxialt text

this is the normal state,

alt text

and this if i roll,

 public Transform target;
     public Vector3 defaultDistance = new Vector3(0f,2f,-10f);
     public float distanceDamp = 10f;
     public float rotationDamp = 2f;
     public Vector3 velocity;
     bool foundTarget;
 
     private void Start()
     {
         foundTarget = false;
     }
 
     // Use this for initialization
     void Update () {
         if (!foundTarget)
         {
             target = GameObject.FindGameObjectWithTag("Ship").transform;
             foundTarget = true;
         }
     }
     
     // Update is called once per frame
     void LateUpdate () {
         SmoothFollow();
 
     }
 
 
     void SmoothFollow()
     {
         Vector3 toPosition = target.position + (target.rotation * defaultDistance);
         Vector3 curPosition = Vector3.SmoothDamp(transform.position, toPosition,ref velocity, distanceDamp);
         transform.position = curPosition;
 
         transform.LookAt(target, target.up);
     }
 
 
     void SmoothFollowLerp()
     {
         Vector3 toPosition = target.position + (target.rotation * defaultDistance);
         Vector3 curPosition = Vector3.Lerp(transform.position, toPosition, distanceDamp * Time.deltaTime);
         transform.position = curPosition;
 
         Quaternion toRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
         Quaternion curRotation = Quaternion.Slerp(transform.rotation, toRotation, rotationDamp * Time.deltaTime);
         transform.rotation = curRotation;
     }
 }
 


idle.png (182.4 kB)
roll.png (210.8 kB)
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 jandd661 · Jul 28, 2017 at 11:50 AM

Is your ship moving in FixedUpdate()?

https://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html

Hope this helps.

Comment
Add comment · Show 2 · 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 DevedGames · Jul 28, 2017 at 12:55 PM 0
Share

Hey, so my ship isnt moving in FixedUpdate, but it also isnt moved by a rigidbody. But thank you for the fast answer.

Also if i move it in FixedUpdat it starts wiggeling :D

avatar image jandd661 DevedGames · Jul 28, 2017 at 02:09 PM 0
Share

sorry, I made an assumption and we know how those go ;D

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

182 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Script has been added to my object but it cannot be found using GetComponent() 1 Answer

First person camera flipping by looking up or down too far. 1 Answer

Same script on two objects, only first one works 1 Answer

Joystick Orientation Wrong After Camera Rotation 1 Answer

Camera zoom out relative to player scale (using CinemachineFreeLook) 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