Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by jensondev · Oct 20, 2012 at 09:06 PM · camerarotationmobileflip

Camera Rotation stay behind player and not flip

Hi,

I'm pretty new to unity development and have been developing a rocket ship that takes off vertically and as it ascends it rotates to fly forwards horizontally. All of this works in my script, but I have a problem getting my camera to track my ship and stay behind it.

The ship is flying in a 3D type game rather than 2D.

My ideal is a camera that is damped, following directly behind the ship, and when the ship turns in any direction the camera follows the back of the ship turning and looking forwards all of the time following in its path.

I have tried making the camera a child of my player, which is fine to some extent but without any script it is very rigid, however the big draw back is that as soon as the ship takes off and rotates to horizontal, the camera moves above it when I want it to stay behind it.

As the game will be mobile based I wanted to avoid using any form of mouse script or additional joystick to allow the player to move the camera where he wants to look, as this will be very difficult to play with the other control buttons in the game.

I have tried using smooth follow, which again is great, but as soon as the rocket rotates below 180 degrees, the camera flips in front of it which again isnt how I would like to to work.

I have attached the following script to my camera which is targetted at my player but currently it will not follow behind the player, but just looks at it. I've tried so many different things im a little at a loss as where to go with this next.

Has anyone got any suggestions as to how I can make this work?

  public GameObject target;
     Vector3 offset;
     public float damping = 1;
     private float rotx = 0.0f;
     private float roty = 0.0f;
     
     void Start()
     {
         offset = transform.position - target.transform.position;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void LateUpdate()
     {
         Vector3 desiredPosition = target.transform.position + offset;
         Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * damping);
         transform.position = position;    
         transform.LookAt(target.transform.position);
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vollmondum · Oct 21, 2012 at 04:51 AM

I'm not sure if it fixes your problem, but try to relocate your game in just one set of coordinates. I mean so that your ship's coordinates never went below 0. The thing you explain might happen because your basic scene is at (0, 0, 0). Set it to like (1000, 1000, 1000) or just set borders for 0 coordinates so that you couldn't fly over those.

Comment
Add comment · 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
0

Answer by jensondev · Oct 21, 2012 at 10:20 PM

Hi thanks for your response, I've tried your suggestion but the camera still flips in front of the player. I've switched to using the smooth follow camera which seems to give me what i'm looking for but I cant seem to stop the camera flipping.

Any ideas?

Comment
Add comment · 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

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

10 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

Related Questions

2D camera rotating relatively to game object speed 0 Answers

fbx animation beats script animation? 2 Answers

Limit camera RotateAround for an UAV game 0 Answers

Camera Script - RtS style, rotation issues 0 Answers

Why this script dont work properly? any ide to fix it? 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