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 Karsnen_2 · Jul 18, 2012 at 06:02 PM · c#cameragameobjectios

Camera to follow a target within a circle?

Hello Devs,

I am working on a script where the camera follows the player (only on 'y' axis). If the player moves in X or Z axis I would like the camera to follow only when the player moves beyonds a circle with a radius 'r' and the origin as camera's X & Z co-ordinates.

To brief it in another view, I would like to have camera's co-ordinates (X & Z) as origin and with a radius r, I want to create a imaginary circle. Lets say a gameobject is a target for the camera and the camera is following the target across Y axis. I would like the camera to follow the player, one and only if it moves beyond the CIRCLE.

I did try out but I got stuck at a certain point. The code is as follows,

 Vector2 DrawCircle(float originX, float originY, float r)
 {
 
  Vector2 cir;
     
  for (int i= 0; i < 180; i++)
     
  {

 

 Circle.x = r * Mathf.Cos(i*Mathf.DegToRad) + originX;
         Circle.y = r * Mathf.Sin(i*Mathf.DegToRad) + originY;
         cir = new Vector2(Circle.x, Circle.y);
  return cir;
     } 
 }

Please do help me, if you could. If you think any other solution, kindly let me know.

Thank you and Please,

Karsnen.

Comment
Add comment · Show 2
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 Karsnen_2 · Jul 18, 2012 at 06:37 PM 0
Share

How about I use a cylindrical collider and then instruct the camera to follow the gameobject on CollisionExit and Not to follow the player on CollisionEnter.

Again I have optimization concerns, as it would be run throughout the entire game and the target platform is ios?

avatar image Mortoc · Jul 18, 2012 at 07:23 PM 0
Share

I'm having trouble understanding what you're trying to accomplish, could you draw a diagram or something visual?

Why are you recalculating this per frame? Why not create a disc mesh and just scale/translate it around?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Jul 18, 2012 at 10:10 PM

Put this script on your camera (untested):

 var radius = 5f;
 var target : Transform; // drop your target here or assign it somewhere
 
 function Update()
 {
   if ((target.position - transform.position).magnitude >= radius)
     transform.LookAt (target);
 }
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 Karsnen_2 · Jul 19, 2012 at 02:15 PM 0
Share

Thanks Dave. Testing it right away...

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Camera follow an object within a circle? 1 Answer

C# Rotate GameObjects Regardless of List Size 2 Answers

Ride across a tree? 1 Answer

How to detect an object which be in FOV of certain camera ? 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