Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 GodofWar · Jul 31, 2015 at 09:52 AM · objecttagoculus

Camera move to location tagged object

Hello guys,

I am learning the basics of programming (Im a visual artist) and currently I am trying to make a demo with the Oculus Rift. I am trying to create a hands free movement in an environment just as this demo (https://www.youtube.com/watch?v=Ad-Aa3ATbyE) Where at 0:30 seconds the person is looking at an object (or tag) and after a while the camera wil move to that location. This is what I am trying to recreate. I started with the Find Closest Enemy example, but I am not sure if I am on the right track.

If anything is unclear, let me know and I will try to clear things up.

Help would be appreciated!

/EDIT/ Here is the code that I have so far:

 using UnityEngine;
 using System.Collections;
 
 // Find the name of the closest enemy
 
 GameObject FindClosestEnemy() {
     GameObject[] gos;
     gos = GameObject.FindGameObjectsWithTag("Enemy");
     GameObject closest = null;
     float distance = Mathf.Infinity;
     Vector3 position = transform.position;
     foreach (GameObject go in gos) {
         Vector3 diff = go.transform.position - position;
         float curDistance = diff.sqrMagnitude;
         if (curDistance < distance) {
             closest = go;
             distance = curDistance;
         }
     }
     return closest;
 }
 }

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 Imankit · Jul 31, 2015 at 11:03 AM 0
Share

Post some code man..

avatar image GodofWar · Jul 31, 2015 at 12:08 PM 0
Share

Added, thanks

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Rob1508 · Jul 31, 2015 at 12:28 PM

I think the best solution would be to cast a ray from your camera into the scene. If you put your "lookable" objects onto one layer, you can use this as your mask layer for the raycast. The reason for this is that the ray just hits objects that you can move to and does not get disturbed by other objects that might be between your camera and a lookable object.

Once you have a hit you can do some visual effects like highlighting and so on. After a short period of time, lets say 1 second, you can check if the ray is still hitting that particular object. If this is true, move your camera towards that object.

I've created a sample scene to demonstrate this. The only thing you have to do is import Unity's standard assets to get a FPS Controller for the mouse look script that is attached.

https://dl.dropboxusercontent.com/u/59805598/Lookable.zip

Cheers! Rob

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 GodofWar · Jul 31, 2015 at 12:55 PM 0
Share

Thank you so much for the scene! Really helpful and I will dig through everything so I will understand it better. Thanks again!

avatar image GodofWar · Jul 31, 2015 at 03:11 PM 0
Share

Thanks again for the scene, I got it working with the Oculus and it helps a lot with understanding rays and the layers.

avatar image Rob1508 · Jul 31, 2015 at 03:13 PM 0
Share

Sure, let me know if you need additional help ;)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Drag Script Not Working 1 Answer

Move from one object to another 0 Answers

Can't Return the Tag of a Child Object 4 Answers

Destroy objects by clicking on them 1 Answer

How can i find a player prefab and add them to a list?????? 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