Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Om3n · Aug 10, 2011 at 11:34 PM · cameramovementgameobjectmousedynamic

Camera movement question

Hi, I'm trying to move the camera from a certain view one gameobject to another one based off mouse click. Ive tried a few different things but cannot seem to achieve this. There doesn't seem to be much similar in tutorials or the unity forums. If someone could point me on the right track or to something i may have missed on the forums it would be greatly appreciated. Thanks.

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

1 Reply

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

Answer by roamcel · Aug 11, 2011 at 12:55 PM

If I correctly understand your question, your only need is to change the camera transform.

 1- add a collider to your object
 2- in your object's script add the following function
 
 void OnMouseDown() {
   Camera.main.transform.position = otherobject.transform.position + cameraoffsetvector;
 }

cameraoffsetvector is a vector which displaces your camera into its viewport position (otherwise it'll just cohincide with otherobject's transform)

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 Om3n · Aug 11, 2011 at 03:17 PM 0
Share

Wow that seems much simpler then the process i was thinking about in my head. Thank you very much. Although wouldn't otherobject error out in the script?.. Ok figured i better double check first. I do get the error, so I'm assu$$anonymous$$g it was just general and I'd need to define otherobject somewhere? Basically whats happening after object load in the world view(from sql) and the camera stays on the initial spot.(before asking the question) ultimately id like it to load to one of the players objects and have the ability to click nearby objects (separated by scenes or view distance) and have the camera move to that location and do it's slow orbit around the object. Unfortunately there doesn't seem to be a lot of camera reference for me in regards to anything like this and im not the best developer. Thank you again for the input.

avatar image Om3n · Aug 11, 2011 at 04:34 PM 0
Share

Ok i understand more now. Thank you again it was really helpful and so simple!

avatar image roamcel · Aug 11, 2011 at 06:04 PM 0
Share

I'm sorry if it was not very clear. 'otherobject' is your local reference to the 'other' object that will s$$anonymous$$l the camera. Usually, you specify it as a public variable in your script, and you drag it in the inspector from the scene hierarchy, or you get it with something like

GameObject otherobject = GameObject.Find("myotherobjectinthescene");

In your particular case, you'll need to come up with a script that returns the gameobject you click upon, so you possibly need to:

1- put your camera swapping script on the camera or another persistent object

2- whenever you click on an object, you trigger the camera's resident script which set the 'otherobject' variable

3- call the function to swap camera

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotating GameObject Around Player With "Mouse Y" Position 2 Answers

Assign mouse events for gameobject/collider at runtime 1 Answer

Rotate the camera around a gameObject with a dynamic up value. 0 Answers

How do I move the player towards the direction of the camera using cinemachine? 0 Answers

GameObject follow the mouse 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