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 gdv · Dec 10, 2014 at 02:47 PM · movementsmoothflashlighty

Smooth Flashlight Movement

Hey! I want to make a smooth flashlight movement but the spotlight only moves smoothly to the x of the camera, and not to the y too.

Here's the script:

 var target : GameObject;
 var speed : float;
 
 function Update() {
     transform.rotation = Quaternion.Slerp (transform.rotation, target.transform.rotation, Time.smoothDeltaTime * speed);
 }


What's the problem?

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
0

Answer by MrSoad · Dec 10, 2014 at 02:46 PM

Try this, I'm assuming you want it to work in relation to the Main Camera :

 #pragma strict
 
 //Transform vars.
 private var tMy_Transform : Transform;
 private var tMain_Camera_Transform : Transform;
 
 //Rotate speed var.
 private var fMy_Rotate_Speed : float;
 
 function Awake () {
 
     //Connect to Objects and Scripts.
     tMain_Camera_Transform = GameObject.Find("Main Camera").transform;
 }
 
 function Start() {
 
     //Get Transforms.
     tMy_Transform = transform;

     //Set Rotation Speed.
     fMy_Rotate_Speed = 8f;
 }
 
 function Update() {
 
     if (tMain_Camera_Transform != null) {
         //Rotate. 
         tMy_Transform.rotation = Quaternion.Slerp(tMy_Transform.rotation, tMain_Camera_Transform.rotation, Time.deltaTime * fMy_Rotate_Speed);

     } else {
         //Try and find Main Camera again.
         tMain_Camera_Transform = GameObject.Find("Main Camera").transform;
     }
 }



Comment
Add comment · Show 2 · 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 gdv · Dec 14, 2014 at 09:16 AM 0
Share

No difference, the spotlight still rotates only to the x axis, I want it to rotate to both axis, x and y. Thanks anyway!

avatar image MrSoad · Dec 14, 2014 at 05:22 PM 0
Share

Odd, this works 100% on the Flashlight in my scene(I just tested it again to be absolutely sure). The problem is somewhere else, not the script, so :

Have you got a rigidbody on your flashlight? If you have then have you restricted the y rotation axis in the rigidbody settings?

Is your flashlight setup(aligned) along the correct axis?

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

How to move smoothly without using iTween? 1 Answer

Smooth Camera Follow Script, Weird Movement... Please help! 1 Answer

Can't force my circle sprite to move/rotate smoothly. Code is very simple. 0 Answers

Smooth Character Movement 1 Answer

Smooth Attached Object 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