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 NinjaRubberBand · Dec 26, 2013 at 12:22 PM · camerarotateenemysmooth

Make my camera turn smoothly

My script does that when i collide with a special gameobject, the camera points at the enemy. It all works but the camera just looks directly at the enemy, and does not turn slowly. How do i make it turn smoothly ?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by azmat786n · Dec 26, 2013 at 04:08 PM

 var target : Transform;
 var distance = 3.0;
 var height = 3.0;
 var damping = 5.0;
 var smoothRotation = true;
 var rotationDamping = 10.0;
 
 function Update () 
     {    
         var wantedPosition = target.TransformPoint(0, height, -distance);
         transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
 
         if (smoothRotation) {
             var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
             transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
         }
 
         else transform.LookAt (target, target.up);
     }
 
 
Comment
Add comment · 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
0

Answer by NinjaRubberBand · Dec 26, 2013 at 05:27 PM

Oh it didn't take my script with, here is the script that i made:

pragma strict

var target : Transform; var look : boolean = false;

function OnTriggerEnter (other : Collider) { if(other.tag == "Wall")

GameObject.Find( "First Person Controller" ).GetComponent(FPSInputController).enabled = false;

GameObject.Find( "First Person Controller" ).GetComponent(CharacterMotor).enabled = false;

GameObject.Find( "First Person Controller" ).GetComponent(MouseLook).enabled = false;

GameObject.Find( "Main Camera" ).GetComponent(MouseLook).enabled = false;

look = true;

yield(WaitForSeconds(5));

GameObject.Find( "First Person Controller" ).GetComponent(FPSInputController).enabled = true;

GameObject.Find( "First Person Controller" ).GetComponent(CharacterMotor).enabled = true;

GameObject.Find( "First Person Controller" ).GetComponent(MouseLook).enabled = true;

GameObject.Find( "Main Camera" ).GetComponent(MouseLook).enabled = true;

look = false;

}

function Update () {

if(look == true)

transform.LookAt(target);

}

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 azmat786n · Dec 26, 2013 at 08:12 PM 0
Share
 var target             : Transform; 
     var look             : boolean = false;
     var fpsInput         : FPSInputController;
     var character$$anonymous$$otor     : Character$$anonymous$$otor;
     var mouseLook         : $$anonymous$$ouseLook;
     var mouseLook2        : $$anonymous$$ouseLook;
     
     function Start() {
         fpsInput         = GameObject.Find("First Person Controller").GetComponent(FPSInputController);
         character$$anonymous$$otor     = GameObject.Find("First Person Controller").GetComponent(Character$$anonymous$$otor);
         mouseLook         = GameObject.Find("First Person Controller").GetComponent($$anonymous$$ouseLook);
         mouseLook2         = GameObject.Find("$$anonymous$$ain Camera").GetComponent($$anonymous$$ouseLook);
     }
     function OnTriggerEnter (other : Collider) {
         if(other.tag == "Wall") {
             DisableComponents();
         }
     }
     function DisableComponents() {
         fpsInput.enabled = false;
         character$$anonymous$$otor.enabled = false;
         mouseLook.enabled = false;
         mouseLook2.enabled = false;
         look = true;
         yield WaitForSeconds(5);
         EnableComponents();
         look = false;
     }
     function EnableComponents() {
         fpsInput.enabled = true;
         character$$anonymous$$otor.enabled = true;
         mouseLook.enabled = true;
         mouseLook2.enabled = true;
     }
     function Update () {
         if(look == true) {
             transform.LookAt(target);
         }
     }

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

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

Related Questions

Rotate camera with easeout 0 Answers

Smooth Camera Rotate 2 Answers

How to rotate the camera smoothly for just 1 second? 2 Answers

camera smooth stop (continuously sliding), on touch end 0 Answers

Turn page, smooth rotate 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