• 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
Question by Karsnen_2 · Sep 24, 2012 at 12:57 PM · c#camerarotation

Camera to follow the player in the form of radius

Hello Devs,

What do I have :

A top-down game where a camera follows the player. It is on X-Z plane. For now the camera follows the player across X-Z plane by the player's global position and mainatains a certain height from the player. The center of the level is a cylinderical object thats spans for the entire height of the level.

When do I think would happen?

The player is free to roam around the level (X-Z) but at certain point, the player might tend to get near the cylindrical object. Hence I would like to change the behaviour of the camera at that particular instance.

What do I want :

When the player reaches near a cylindrical object (say Radius 'r' from the center), I would like to camera to lock its position i.e. maintain the distance (radius) from the cylinder. But as the player has the freedom to move around the cylinderical object, there are exceptions when it gets out of the camera's view. Hence at this instance, I would like the player to rotate around the cylinderical object when the player does so.

Image Representation :

  1. First Image : The camera follows the player above its global position.

  2. Second Image : The player enters a radius 'r' from the center of the cylinder. Hence the player stops following and locks it's distance from the player.

  3. Third Image : An exception that is caused is the movement of the player within the radius 'r' from the center. Hence in order to have the player inside the view of the camera, the camera follows the player by maintaining a distance and thus suffer rotation.

  4. Fourth Image :Player moves and so does the camera. The rotation is similar to a merry-go-round.

Thank you once again,

regards,

Karsnen.

Comment

People who like this

0 Show 1
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 T27M · Sep 24, 2012 at 04:05 PM 0
Share

Could you post your current script ?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by T27M · Sep 24, 2012 at 06:11 PM

This isn't really an answer.

But you could take a look at transform.RotateAround(). I set up a scene like you described and used the position of the cylinder as the point to rotate around.

Then I used Vector3.Distance() to check how far the camera was from that point. I then rounded the value it gave me back Mathf.Round() and tried an If statement to start rotating when I was a certain distance.

 if ( distance to cylinder <= radius or a suitable distance)
     transform.RotateAround(cylinder, vector3.up, rotateSpeed * time.deltatime);


I also cast a ray from the camera to the player to check if anything was in the way such as the cylinder and then stated rotating like above.

Problem is it behaves differently depending on how your camera is setup, plus it only rotates one way around at the moment.

Hope its of some use to you until someone more knowledgeable comes along.

Comment
Karsnen_2

People who like this

-1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Flip over an object (smooth transition) 3 Answers

How can I rotate the camera around an object? 1 Answer

Help with rotating Camera around Pivotpoint(from A to B) 1 Answer

Why is the camera going crazy when the player moves? 0 Answers

Camera rotation C# script problem 3 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