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 Pariah Silver · Feb 27, 2013 at 08:14 PM · camerarotateorbit

Having trouble making my camera orbit an object

I've got simple planetary bodies orbiting a sun, that works fine. However, I have a fixed camera for each planet (every planet is a prefab combination of planet and child camera). I'm trying to get the camera to rotate around the planet, always facing it, by use of arrow keys.

 if(Input.GetKey(KeyCode.LeftArrow)){
         transform.RotateAroundLocal(Vector3(0, -CameraRotate, 0), CameraRotate * Time.deltaTime);
         transform.localPosition(0, 0, 0);
 }

The first line works just fine, and rotates the camera to the left. I have an identical code group that does the opposite.

My problem is the second line. I initially assumed that it would reference the camera itself, just like the line above. Unfortunately, I get the following error:

 BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Vector3'.

Unless I'm wrong, this means I'm not referencing the camera but instead attempting to tell the entire game to rotate. Is that right? I've tried every variation I can think of, from Object.tranform to gameObject.transform; they work, to a point, but I get a null error telling me an object is being referenced that isn't there (probably misremembering that).

Comment
Add comment · 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 Pariah Silver · Feb 27, 2013 at 09:04 PM 0
Share

I'm using java actually. I forgot to mention that.

I tried adding 'new' as you suggested, but it didn't change a thing. Everything seems to function exactly as without the 'new' there; the camera still just spins where it is, rather than rotating around its parent.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AlvinHerawan · Mar 19, 2013 at 02:50 AM

So far I've been exploring about camera scripting on the Asset Store. One solution I found was from the Camera Orbit Tool where you parent your camera to an empty game object and rotate that game object instead of the camera. This will give a distance between the camera and the object that the camera is orbiting.

So in your case, you might want to create an empty game object on each planet and parent your camera to that empty game object. You can then attach a script to rotate the parent, causing the camera to orbit each planet.

I hope I get your question right and get your problem solved.

Comment
Add comment · Show 2 · 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 Pariah Silver · Mar 20, 2013 at 05:47 AM 0
Share

Oh, that's an interesting idea! I'll have to give it a try.

avatar image AlvinHerawan · Mar 20, 2013 at 06:12 AM 0
Share

In a little different condition, you might want to check on this thread: http://answers.unity3d.com/questions/418421/set-camera-orbit-rotation-on-mouse-direction-mouve.html

robertbu's accepted answer is really good.

avatar image
0

Answer by robertbu · Feb 27, 2013 at 09:46 PM

Your problem is on the third code line. I think you want:

 if(Input.GetKey(KeyCode.LeftArrow)){
         transform.RotateAroundLocal(Vector3(0, -CameraRotate, 0), CameraRotate * Time.deltaTime);
         transform.localPosition = Vector3(0, 0, 0);

}

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 Pariah Silver · Feb 27, 2013 at 10:26 PM 0
Share

Well that clears my error, and I see now what I did wrong with the line, so thanks for that.

However, this isn't doing what I'd hoped it would do. Rather than orbit my camera around its planet, always facing that planet, the camera simply spins around in place.

Is there something I'm missing about RotateAroundLocal?

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

Camera Orbit Rotation Problem 0 Answers

Slowly orbit camera on keypress 1 Answer

Help with camera movement using mobile input 0 Answers

Orbit around an object 0 Answers

How to rotate the camera smoothly for just 1 second? 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