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 Red Sentinel · Apr 13, 2013 at 06:08 AM · camerajavascriptcolliderrotate

Click on collider to rotate camera

Hi everyone. I have come across a problem where I can't get my camera to rotate when I click on a collider. I want to be able to click on a collider and have the camera rotate to look at a different collider. I am trying to create a more "interactive" menu but so far it has gone nowhere as I cannot seam to fix this. I'm new to scripting, so if possible it would be nice to get any ideas in JavaScript.

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 Chronos-L · Apr 13, 2013 at 07:11 AM 0
Share

What you already have now? Can you post it here? Be more precise in your description, get my camera to rotate when I click on a collider can mean any of these 3 (or perhaps more):

  1. Click on collider, camera rotate and look at collider

  2. Click on collider, camera rotate in a specific axis

  3. Click on collider, camera rotate randomly (shaking?)

avatar image Red Sentinel · Apr 13, 2013 at 08:17 AM 0
Share

Sadly I don't have anything at the moment (as I said I'm new to scripting) but click on collider, camera rotate and look at collider fits what I want most.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chronos-L · Apr 13, 2013 at 09:39 AM

Combine these 3:

  • Physics.Raycast

  • Transform.LookAt

  • Input.GetMouseButtonDown

C# example

 void Update() {
    if( Input.GetMouseButtonDown(0) ) { //Left Click
       Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
       RaycastHit hit;
       if( Physics.Raycast( ray, out hit ) ) {
          Camera.main.transform.LookAt( hit.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 Red Sentinel · Apr 15, 2013 at 03:46 AM 0
Share

Can you explain what happens in this, because I don't really understand C# very well. Thanks

avatar image Chronos-L · Apr 15, 2013 at 03:51 AM 0
Share
 void Update() {
    //Detect for a left mouse click
    if( Input.Get$$anonymous$$ouseButtonDown(0) ) { 
 
       //Create a ray that is ai$$anonymous$$g at where your mouse is ai$$anonymous$$g
       Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
       //This will store the raycast information
       RaycastHit hit;
 
       //return true when the ray hit something, store information in the hit-variable
       if( Physics.Raycast( ray, out hit ) ) {
          //call the lookat function of the camera's transform to point/lookAt the hit gameObject
          Camera.main.transform.LookAt( hit.transform );
       }
    }
 }
avatar image Red Sentinel · Apr 15, 2013 at 04:04 AM 0
Share

Great thanks. I'll try this out soon

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

11 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 avatar image

Related Questions

Slowly orbit camera on keypress 1 Answer

Rotate an Object 1 Answer

Camera scripting references 0 Answers

Set Max Rotation On Weapon Sway 0 Answers

Limiting Camera Movement 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