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 /
avatar image
0
Question by smirlianos · Jan 02, 2013 at 07:01 PM · camerarotationjavascriptquaternioncamera-look

A little help with this camera script please?

I have downloaded from internet this camera script for smooth follow

 using UnityEngine;
 using System.Collections;
 
 public class FollowCamera : MonoBehaviour {
     public GameObject target;
     public float damping = 1;
     Vector3 offset;
     
     void Start() {
         offset = target.transform.position - transform.position;
     }
     
     void LateUpdate() {
         float currentAngle = transform.eulerAngles.y;
         float desiredAngle = target.transform.eulerAngles.y;
         float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
         
         Quaternion rotation = Quaternion.Euler(0, angle, 0);
         transform.position = target.transform.position - (rotation * offset);
         
         transform.LookAt(target.transform);
     }
 }

The problem is that it sets the camera to a position related to the player like this in the imagealt text

I wanted the camera to have a rotation like this, being more "horizontally" alt text

I have no idea how to change that, can someone help me?? (The camera is in the scene in position B, but when I start the game, it goes to the position A) image : http://imageshack.us/photo/my-images/202/39794077.png/

1.png (176.6 kB)
2.png (66.6 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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Lovrenc · Jan 02, 2013 at 07:13 PM

What you can do is add a simple object (that you wont render) as a child to your player (or cube in this case) and add that child to this camera script as a target.

Comment
Add comment · Show 3 · 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 smirlianos · Jan 02, 2013 at 07:19 PM 0
Share

I did, it has the same effects

avatar image Julien-Lynge · Jan 02, 2013 at 07:20 PM 0
Share

You have to offset the new target from the cube - move it above the cube.

avatar image smirlianos · Jan 02, 2013 at 07:30 PM 0
Share

Nice trick, it worked!

avatar image
0

Answer by Julien-Lynge · Jan 02, 2013 at 07:08 PM

In the Start() method, the script creates an 'offset' parameter based on where the camera is placed relative to the target. You need to adjust the start position of the camera to be where you want it relative to the target. When the script starts, it will 'lock' to that offset.

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 Lovrenc · Jan 02, 2013 at 07:16 PM 0
Share

This isnt the problem. He has the camera where he wants, he wants it to look above the character not directly into it if i understood correctly.

avatar image Julien-Lynge · Jan 02, 2013 at 07:18 PM 0
Share

S/he only mentioned wanting a different rotation (which to me implies a different offset), but yeah, from the screenshot I can see what you mean.

avatar image smirlianos · Jan 02, 2013 at 07:26 PM 0
Share

Actually a different rotation and position

The camera is in the scene in position B, but when I start the game, it goes to the position A) image : http://imageshack.us/photo/my-images/202/39794077.png/

avatar image Lovrenc · Jan 02, 2013 at 07:29 PM 0
Share

I see nothing in this script that would move your camera relative to the target. In this sense answer above seems absolutely correct. It does however fix where camera is looking directly on the target. For that i sugges a child as stated below.

avatar image
0

Answer by Landern · Jan 02, 2013 at 07:09 PM

You need to change the offset which is going to be the distance from the target. Modify desiredAngle initialization to change the viewing angle.

Comment
Add comment · Show 1 · 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 smirlianos · Jan 02, 2013 at 07:17 PM 0
Share

How can I do that? I have zero knowledge of C# !!

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

11 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

Related Questions

Rotation along the x-axis to that player can turn around? 1 Answer

Rotating Main Camera 1 Answer

Rotate object following mouse movement. Object jumps/ flips 1 Answer

Lerp Third Person Camera Rotation 1 Answer

Camera rotation script logic error? 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