Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MobinS · Aug 18, 2011 at 10:22 PM · lookattarget

"look at target" problem

hey... I asked sth that mr. aldo nalleto answered me... it works good But I have a problem! this script will look at the target but not perfectly... it just change the rotation of Y... I don't know what to do... if you played fallout you see that when we start chat with someone every thing will stop and camera will go on the person ( target) I exactly want that. thanks to aldo the script just work great but looking doesn't... I want that when I placed an object in 3d world and put that as target in this script , the camera go just on that object , from any angle , any place , just go on that... if any one can edit this to the one that I sayed it would be great ...( and this is the full script that mr. aldonalleto told:)

 using UnityEngine;
 using System.Collections;
 public class Treeger : MonoBehaviour
 {
 
     public GameObject MC;
     public Transform target;
     public float timeLook = 0.5f;
     public float timeWait = 4f;
 
     void Start()
     {
         MC = GameObject.Find("Durbin Asli");
     }
    
     bool looking = false;
 
     IEnumerator OnTriggerEnter(Collider obj)
     { // make OnTriggerEnter a coroutine
         CharacterControl.tree--;
         audio.Play();
         if (looking) ; // does nothing if already looking  
         looking = true; // I'm going to look
         EnableScripts(obj.transform, false); // disable all obj scripts
         EnableScripts(MC.transform, false); // disable all camera scripts
         Quaternion rot1 = MC.transform.rotation; // save initial direction
         // define target direction in rot2
         Quaternion rot2 = Quaternion.LookRotation(target.position - MC.transform.position, Vector3.up);
         for (float t = 0f; t < 1f; )
         { // look at target in timeLook seconds
             t += Time.deltaTime / timeLook;
             MC.transform.rotation = Quaternion.Lerp(rot1, rot2, t);
             yield return null;
         }
         yield return new WaitForSeconds(timeWait); // wait timeWait seconds
         for (float t = 0f; t < 1f; )
         { // return to original direction in timeLook seconds
             t += Time.deltaTime / timeLook;
             MC.transform.rotation = Quaternion.Lerp(rot2, rot1, t);
             yield return null;
         }
         EnableScripts(obj.transform, true); // enable obj scripts
         EnableScripts(MC.transform, true); // enable camera scripts
         looking = false; // finished looking
         Destroy(gameObject);
     }
 
 void EnableScripts(Transform owner, bool onOff){
   MonoBehaviour script;
   script = owner.GetComponent<MouseLook>();
   if (script) script.enabled = onOff;
   script = owner.GetComponent<FPSWalker>();
   if (script) script.enabled = onOff;
   script = MC.GetComponent<MouseLook>();
   if (script) script.enabled = onOff;
 }
 
 
 
 
     }
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 aldonaletto · Aug 19, 2011 at 12:05 AM

Hi @MobinS. In my tests this script works perfectly: when the character enters the trigger, its scripts are disabled and the camera gradually turns to the target position, wait for timeWait seconds, then returns gradually to the original direction.
There are two possibilities in your case:
1- the target pivot is way out of the mesh's center;
2- the camera script is not being disabled, and is "fighting" with your script.
I bet on the second alternative: in the First Person Controller the camera script is responsible for the up/down movement, so you will have a problem like you've described if it doesn't get disabled. EnableScripts tries to disable a camera script named MouseLook - it will fail if the camera script isn't MouseLook. Click the Main Camera object and check which script it uses.

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 MobinS · Aug 19, 2011 at 02:10 PM 0
Share

thnx aldo! YOU are just perfect ;) it was Bcause of Character Joint ! I deleted it and it worked perfectly!!! ;) thnx!

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

Bone lookat do not work Help! 1 Answer

Lose connection to dragged variable when making prefab 1 Answer

LookAt(target) Not Always Working... Any Ideas? 0 Answers

Finding the closest gameobjects in a radius 1 Answer

lookAt on Y axis only 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