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 ROM · Jul 04, 2010 at 01:24 PM · pivotcenter

Rotating camera around point?

So basically I want the Camera to follow my character looking down on it. The problem is the character doesn't walk on a flat plane, rather it walks around a sphere. So essentially the camera should follow the character around the sphere pivoting around the centre point like in the below image. Does anyone have any idea how to do this?

alt text

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by pyro · Jul 04, 2010 at 03:05 PM

In this case I think the camera movement would be a little jerky if you parented it directly to the character (which is one simple way to accomplish what you want), but I guess it depends on how you want your game to look.

Here is another way of doing it (there are many):

1) Create an empty GameObject and set it above your character about where you want the camera to be, and then parent it to your character

2) Create a script to smoothly seek the camera to that GameObject's transform's position (with Mathf.SmoothDamp) while looking at it (with Transform.LookAt)

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 tingham · Jul 04, 2010 at 01:54 PM

Positions inside of the character's local translation don't change based on the orientation of the object in world space. In this case I think you can parent the camera to the character and simply transition between points on the axis; inside of the character transform.

From here you can slerp between those points to create spherical animations.

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 StephanK · Jul 04, 2010 at 03:19 PM

Why not use the SmoothFollow script from StandardAssets?

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 KhShani · Mar 14, 2014 at 01:32 PM

using UnityEngine; using System.Collections;

/// /// Стандартный Smooth follow, переписанный на C#. /// Камера привязывается к объекту и плавно следит за ним /// public class SmoothFollow : MonoBehaviour { public Transform Target; // The distance in the x-z plane to the target public float Distance = 10.0f; // the height we want the camera to be above the target public float Height = 5.0f; // How much we public float HeightDamping = 2.0f; public float RotationDamping = 3.0f;

 public bool smooth;
 public float smoothMultiplier;

 public bool dontLookAt;

 Transform tform;
 
 // Use this for initialization
 void Start ()
 {
     tform = transform;
 }
 
 void LateUpdate()
 {
     // Early out if we don't have a target
     if (Target == null)
         return;



 //    Target.transform.Rotate(Vector3.up * Time.deltaTime * 20);

     // Calculate the current rotation angles
     float wantedRotationAngle = Target.eulerAngles.y;
     float wantedHeight = Target.position.y + Height;
         
     float currentRotationAngle = tform.eulerAngles.y;
     float currentHeight = tform.position.y;
     
     // Damp the rotation around the y-axis
     currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, RotationDamping * Time.deltaTime);
 
     // Damp the height
     currentHeight = Mathf.Lerp(currentHeight, wantedHeight, HeightDamping * Time.deltaTime);
 
     // Convert the angle into a rotation
     Quaternion currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
     
     // Set the position of the camera on the x-z plane to:
     // distance meters behind the target
     Vector3 targetPosition = tform.position;
     targetPosition += (Target.position - tform.position);
     targetPosition -= currentRotation * Vector3.forward * Distance;
     if (smooth)
         tform.position = Vector3.Lerp(tform.position, targetPosition, Time.deltaTime * smoothMultiplier);
     else
         tform.position = targetPosition;
 
     // Set the height of the camera
     tform.position += new Vector3(0, (currentHeight - tform.position.y), 0);
     
     // Always look at the target
     if (!dontLookAt)
         tform.LookAt(Target);
 }

}

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

1 Person is following this question.

avatar image

Related Questions

how to center pivot after combine mesh? 0 Answers

Rigidbody and addforce to center of object? JS 2 Answers

(ProBuilder) SetPivot is not working. 0 Answers

How to scale an object from center pivot in code 0 Answers

How do you get the world-space position of a sprite with a custom pivot? 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